This is my build step
This is the produced log
2017-10-23T12:46:42.8958745Z ##[section]Starting: dotnet run Tools
2017-10-23T12:46:42.8958745Z ==============================================================================
2017-10-23T12:46:42.8958745Z Task : .NET Core
2017-10-23T12:46:42.8958745Z Description : Build, test and publish using dotnet core command-line.
2017-10-23T12:46:42.8958745Z Version : 1.0.2
2017-10-23T12:46:42.8958745Z Author : Microsoft Corporation
2017-10-23T12:46:42.8958745Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
2017-10-23T12:46:42.8958745Z ==============================================================================
2017-10-23T12:46:43.3968589Z [command]"C:\Program Files\dotnet\dotnet.exe" run d:\a\1\s\Tools\Tools.csproj --configuration test
2017-10-23T12:46:43.5008554Z Couldn't find a project to run. Ensure a project exists in d:\a\1\s, or pass the path to the project using --project.
2017-10-23T12:46:43.5138548Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2017-10-23T12:46:43.5138548Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\1\s\Tools\Tools.csproj
2017-10-23T12:46:43.5168542Z ##[section]Finishing: dotnet run Tools
The problem is, the project the task should run is not passed via the --project argument. But how can I do that with the options the build step provides?
Assuming you have a .Net Core console app stored with the following content in a Git repo:
reporoot/
reporoot/Program.cs
reporoot/temp.csproj
to run it with the .net, provide the following arguments to the .Net Core task:
command: run
Projects: *.csproj
Arguments -p temp.csproj
This is a sample output:
2017-10-23T18:14:22.2924112Z ##[debug]C:\Program Files\dotnet\dotnet.exe arg: run
2017-10-23T18:14:22.2924112Z ##[debug]C:\Program Files\dotnet\dotnet.exe arg: d:\a\1\s\temp.csproj
2017-10-23T18:14:22.2924112Z ##[debug]C:\Program Files\dotnet\dotnet.exe arg: -p temp.csproj
2017-10-23T18:14:22.2934125Z ##[debug]exec tool: C:\Program Files\dotnet\dotnet.exe
2017-10-23T18:14:22.2934125Z ##[debug]arguments:
2017-10-23T18:14:22.2934125Z ##[debug] run
2017-10-23T18:14:22.2934125Z ##[debug] d:\a\1\s\temp.csproj
2017-10-23T18:14:22.2934125Z ##[debug] -p
2017-10-23T18:14:22.2934125Z ##[debug] temp.csproj
2017-10-23T18:14:22.2943933Z [command]"C:\Program Files\dotnet\dotnet.exe" run d:\a\1\s\temp.csproj -p temp.csproj
2017-10-23T18:14:36.1934899Z Hello World!
Related
Problem Background:
I have a class library project that contains the database migrations (MyProject.MigrationProject.csproj). And in startup.cs of the entry project (Web API), I have explicitly included migration assembly like following.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
configuration.GetConnectionString("DefaultConnection"),
x => x.MigrationsAssembly("MyProject.MigrationProject")));
Then I run the dotnet ef migration command locally using powershell. The command I'm using is:
dotnet ef migrations script --no-build -o D:\migrations\script.sql --idempotent --project D:\...\src\MyProject.MigrationProject\MyProject.MigrationProject.csproj --startup-project D:\...\src\MyProject.WebApi\MyProject.WebApi.csproj
The above command executes successfully on my machine and creates the desired script.sql file on output location. The same command is then used in the build pipeline (using command line task) in Azure Devops but for some reason it fails there. The command on Devops looks like this:
dotnet ef migrations script --no-build -o $(Build.ArtifactStagingDirectory)\migrations\script.sql --idempotent --project $(Build.SourcesDirectory)\src\MyProject.MigrationProject\MyProject.MigrationProject.csproj --startup-project $(Build.SourcesDirectory)\src\MyProject.WebApi\MyProject.WebApi.csproj
The Error I get from Devops:
Script contents:
dotnet ef migrations script --no-build -o D:\a\1\a\migrations\script.sql --idempotent --project D:\a\1\s\src\MyProject.MigrationProject\MyProject.MigrationProject.csproj --startup-project D:\a\1\s\src\MyProject.WebApi\MyProject.WebApi.csproj
##[debug]AGENT_VERSION: '2.193.1'
##[debug]AGENT_TEMPDIRECTORY: 'D:\a\_temp'
##[debug]Asserting container path exists: 'D:\a\_temp'
##[debug]Asserting leaf path exists: 'C:\Windows\system32\cmd.exe'
========================== Starting Command Output ===========================
##[debug]Entering Invoke-VstsTool.
##[debug] Arguments: '/D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\37fc4a71-a144-4332-9a84-04e6138a2538.cmd""'
##[debug] FileName: 'C:\Windows\system32\cmd.exe'
##[debug] WorkingDirectory: 'D:\a\1\s'
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\37fc4a71-a144-4332-9a84-04e6138a2538.cmd""
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the applicgation service provider. Error: A certificate with the thumbprint 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' could not be found.
Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
##[debug]Exit code: 1
##[debug]Leaving Invoke-VstsTool.
##[error]Cmd.exe exited with code '1'.
##[debug]Processed: ##vso[task.logissue type=error]Cmd.exe exited with code '1'.
##[debug]Processed: ##vso[task.complete result=Failed]Error detected
##[debug]Leaving D:\a\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.182.0\cmdline.ps1.
Finishing: CmdLine
At times, by tweaking the YAML file, I was able to get rid of the first error but the 2nd one never disappeared on devops. The issue is pretty much because of having separate project for Migrations but I think that's how it should be...
My Build pipline's YAML:
trigger:
- develop
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '**/MyProject.WebApi.csproj'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '**/MyProject.WebApi.csproj'
arguments: '--no-restore'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '**/*[Tt]ests/*.csproj'
arguments: '--no-restore --no-build'
- task: DotNetCoreCLI#2
displayName: 'Publish WebApi'
inputs:
command: publish
publishWebProjects: false
projects: '**/MyProject.WebApi.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) --runtime -r $(runtime)'
- task: CopyFiles#2
inputs:
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '5.x'
- task: DotNetCoreCLI#2
displayName: Install dotnet-ef
inputs:
command: 'custom'
custom: 'tool'
arguments: 'install --global dotnet-ef --version 5.0.10 --ignore-failed-sources'
- task: CmdLine#2
inputs:
script: dotnet ef migrations script --no-build -o $(Build.ArtifactStagingDirectory)\migrations\script.sql --idempotent --project $(Build.SourcesDirectory)\src\MyProject.MigrationProject\MyProject.MigrationProject.csproj --startup-project $(Build.SourcesDirectory)\src\MyProject.WebApi\MyProject.WebApi.csproj
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
My Suspicion:
It could be an issue with the directory where the command is executed from (on ADO powershell). I suspect this because, on my local machine, before calling the method x.MigrationsAssembly("MyProject.MigrationProject"), the following command failed when I executed it from a directory other than the entry project's directory but when I navigated the powershell to entry project and executed the same command, it went successful. The command at that time was:
dotnet ef migrations script -o D:\migrations\script.sql --idempotent --project D:\...\src\MyProject.MigrationProject\MyProject.MigrationProject.csproj
I'm already using the same YAML in another project but that contains everything in single Web API project and so, I do not get any issue there.
Question:
What am I doing wrong here? What can I do to fix this issue? Any help would be appreciated.
Project Details
DotNet 5.0
EntityFramewokCore 5.0.10
Visual Studio 2019
If I'm missing anything, please ask.
Updates:
My suspicion about working directory for executing the dotnet ef command appears to be wrong as I tried that by supplying workingDirectory parameter to the command line tasks. It works on local machine though.
Thanks #jane-ma-msft
The Error message shows that it is a Certificate error. Please follow the work around to fix the issue.
Try to generate a new certificate or cancel certificate validation.
Check your .sln file. If it has PackageCertificateKeyFile & PackageCertificateThumbprint please try to remove the properties and restart a pipeline.
Or Check that it is configured correctly and that you have uploaded the correct certificate file to the appropriate path.
Make sure that the agent windows-latest has all the .NET SDK versions you need and all the software your project needs to reference. If not, use the task or command line to download them. Click this link to view the software installed on the windows-latest agent.
If you are using the Microsoft-hosted Windows agents in your pipeline, please try to use the self-hosted Agent in your pipeline. Click this document for detailed steps.
Refer here Link 1 & Link 2
I have the following successful dotnet build release pipeline step configured:
Task version: 2.*
Display name: dotnet build
Command: build
Path to project(s): **/AppConsole.csproj
Arguments:
It is immediately following by a failing dotnet run step:
Task version: 2.*
Display name: dotnet run
Command: run
Path to project(s): **/AppConsole.csproj
Arguments:
Which exits with the message:
[command]C:\agent_dply\_work\_tool\dotnet\dotnet.exe run C:\agent_dply\_work\r40\a\Testing\Tester\AppConsole.csproj
Couldn't find a project to run. Ensure a project exists in C:\agent_dply\_work\r40\a.
Or pass the path to the project using --project
##[error]Error: The process 'C:\agent_dply\_work\_tool\dotnet\dotnet.exe' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects : C:\agent_dply\_work\r40\a\Testing\Tester\AppConsole.csproj
How do I tell the dotnet command where the project is when running under VSTS? I've tried, as it recommends, using the --project flag, but it gives similar errors.
I have a repository which has nothing on master, except the Readme and azure-pipelines.yml YAML. On the development branch (the branch I want to build and deploy and have CI on) there are three folders, MVC, Test, and Console, each containing a project (an MVC version of an ASP.NET Core MVC, .NET Core console, and Xunit test project). I want to run dotnet restore and build on the MVC project, but I get the error:
2019-02-08T15:09:20.9373945Z ##[section]Starting: CmdLine
2019-02-08T15:09:20.9468192Z ==============================================================================
2019-02-08T15:09:20.9468291Z Task : Command Line
2019-02-08T15:09:20.9468353Z Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-02-08T15:09:20.9468441Z Version : 2.146.1
2019-02-08T15:09:20.9468490Z Author : Microsoft Corporation
2019-02-08T15:09:20.9468565Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-02-08T15:09:20.9468629Z ==============================================================================
2019-02-08T15:09:22.4499876Z Generating script.
2019-02-08T15:09:22.5206191Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\21484123-df40-47c7-9383-7f526daaa124.cmd""
2019-02-08T15:09:22.8173263Z MSBUILD : error MSB1009: Project file does not exist.
2019-02-08T15:09:22.8173430Z Switch: MVC
2019-02-08T15:09:23.1247189Z Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
2019-02-08T15:09:23.1308513Z Copyright (C) Microsoft Corporation. All rights reserved.
2019-02-08T15:09:23.1308642Z
2019-02-08T15:09:23.1308714Z MSBUILD : error MSB1009: Project file does not exist.
2019-02-08T15:09:23.1308801Z Switch: MVC
2019-02-08T15:09:23.2993350Z ##[error]Cmd.exe exited with code '1'.
2019-02-08T15:09:23.3158684Z ##[section]Finishing: CmdLine
The YAML file in master is the following:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- dev
- master
pool:
vmImage: 'vs2017-win2016'
#- task: DotNetCoreInstaller#0
# inputs:
# version: '2.2.103' # replace this value with the version that you need for your project
steps:
- script: |
dotnet restore MVC
dotnet build MVC
- task: PublishBuildArtifacts#1
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: PublishBuildArtifacts#1
Is there a way to access MVC for the dotnet commands?
I have an MSTest project that works fine when being executed with:
dotnet test --logger "trx;LogFileName=Result.trx" --settings tests.runsettings
I am also able to build a self-contained app out of it with:
dotnet publish -c Release -f netcoreapp2.1 --force --self-contained --runtime win-x64
But I have no idea how to run the tests from the produced output.
Calling
dotnet test .\ProjectName.dll --logger "trx;LogFileName=Result.trx" --settings tests.runsettings
fails with the message:
error MSB4025: The project file could not be loaded.
Any hints as how to run this self-contaiend MSTest-Project?
dotnet test now (2022) accepts .dll files to perform test execution.
You are using the wrong tool:
➜ ~ dotnet --help
test Runs unit tests using the test runner specified in the project.
vstest Runs Microsoft Test Execution Command Line Tool.
dotnet test is the tool used to run unit tests defined in a given project. If you are trying to run tests out of a published dll, dotnet vstest is the command you should us. You do that like this:
dotnet publish -o outputdir
dotnet vstest outputdir/your.dll
I'm using GitLab CE as our source control system. It's on prem but updated to the latest version.
I have a Runner configured to build .net projects.
I have a dotNet Core Project that I want to build. The problem i'm having is loading the .net Build environments. I'm trying to run this to establish the environment:
`- 'cmd /K "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat"'
This executes correct to the point that I get this output:
$ cmd /K "C:\Program Files ^(x86^)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat"
**********************************************************************
** Visual Studio 2017 MSBuild Command Prompt
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
C:\GitLab-Runner\builds\352e1762\0\online\WebApp>$ nuget restore src/Online-WebApp.sln
MSBuild auto-detection: using msbuild version '15.5.179.9764' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
...rest removed...
The problem is when it gets the job step in the Yml, the msbuild command is reported as not recognized.
Here's the full YAML.
Note that manually setting the PATH worked to find msbuild....
variables:
DATABASE_URL: "example=not-real" #just to show this is an option; https://docs.gitlab.com/ce/ci/variables/README.html
stages:
- build
before_script:
#- 'PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin'
#- 'cmd /K "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"'
#- 'cmd /K "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\LaunchDevCmd.bat"'
- 'cmd /K "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat"'
- 'nuget restore src/Online-WebApp.sln'
# What is important, is that each job is run independently from each other. "build" is a job.
build:
stage: build
script:
- 'msbuild src/Online-WebApp.sln /t:Clean,ReBuild /p:Configuration=Release;Platform="Any CPU"'
- 'dotnet pack src/Online-WebApp/Online-WebApp.csproj -c Release -v d --output nupkgs --no-build'
only:
- master