VSTS dotnet run step does not find build from previous step - .net-core

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.

Related

Unable to install coverlet.console 3.1 plugin in vs 2019 .net frame work 4.5.2 project

In git lab server,I am trying to generate code coverage using yaml file as below script
stage: test
script:
- dotnet test AMSC\AMSC.sln --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
I am able to generate code coverage in opencover format in git server.
the job was failed after generating the code coverage as below screenshort,please let me know any one have solution on this.
code coverage report in CI/CD Pipe line
ERROR: Job failed: exit status 1

GitLab Runner stopping after `dotnet restore` or `dotnet test`

I am new to CI and tried to add the following yaml to our project.
image: microsoft/dotnet:latest
stages:
- test
test:
stage: test
before_script:
- 'echo Stage - Test started'
- 'dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools'
script:
- 'cd "./My Project"'
- 'dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"'
- './tools/reportgenerator "-reports:./Tests/*/TestResults/*/coverage.cobertura.xml" "-targetdir:Reports_Coverage" -reportTypes:TextSummary'
- 'cat ./Reports_Coverage/Summary.txt'
after_script:
- 'echo Stage - Test finished'
On the job I get the following output:
Running with gitlab-runner 13.7.0 (943fc252) on ***
Resolving secrets
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab-pipeline
Using Kubernetes executor with image microsoft/dotnet:latest ...
Preparing environment
Running on*** via ***...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/***/.git/
Created fresh repository.
Checking out 07e98444 as ***...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ echo Stage - Test started
Stage - Test started
$ dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
You can invoke the tool using the following command: reportgenerator
Tool 'dotnet-reportgenerator-globaltool' (version '4.8.4') was successfully installed.
$ cd "./My Project"
$ dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"
Running after_script
Running after script...
$ echo Stage - Test finished
Stage - Test finished
Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1
I tinkered around a little bit and realized, that this minified yaml also fails:
image: microsoft/dotnet:latest
stages:
- test
test:
stage: test
before_script:
- 'cd "./My Project"'
- 'dotnet restore'
script:
- 'dotnet test --no-restore'
This generates an equal output, except it stops at dotnet restore.
I honestly don't know what to do, since this is the most minified version of a test I found.
Did I mess up something within the project, or is the problem within the GitLab Runner itself?
Project Version: .net Core App 3.1
Not a real solution, but I found the issue behind this. You can set the verbosity level of the dotnet test command (documentation). While doing so, I found out that you obviously cannot run a WPF project within a Linux based GitLab Runner.

Install & run custom dotnet tool on azure devops release

I'm trying to build a Release pipeline that is triggered by a new version of a published dotnet core tool. The trigger works fine, but I'm unable to install and run the tool in my Tasks.
CURRENTLY:
Running a Command Line Task results in a 401:
dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp
C:\Program Files\dotnet\sdk\3.0.100\NuGet.targets(123,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\h0g1c35v.eny\restore.csproj]
C:\Program Files\dotnet\sdk\3.0.100\NuGet.targets(123,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\h0g1c35v.eny\restore.csproj]
The tool package could not be restored.
Tool 'myapp' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
This leads me to believe that I'm missing something here, making it more complicated than it needs to be, or thinking about this the wrong way. The tools in the feed can be installed locally, so I believe it's my release approach.
I'm currently looking into Personal Access Tokens (PAT)
PREVIOUSLY:
If I use the .Net Core task and the custom option:
The logs show a malformed command passed to dotnet.exe:
[command]"C:\Program Files\dotnet\dotnet.exe" "dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp"
or
[command]"C:\Program Files\dotnet\dotnet.exe" "tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp"
I've tried varying arguments and I tend to always see the same error message:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Your custom dotnet command is quoted and dotnet is repeated : dotnet.exe" "dotnet tool install ..." so the command is misinterpreted.
You can use the Command Line task and set the dotnet command directly :
dotnet tool install -g --add-source=https://pkgs.dev.azure.com/<org-name>/_packaging/Tools/nuget/v3/index.json MyApp
Using the .Net Core task works perfect for us.
Since the dotnet command is quoted, you need to set tool as the command and update into arguments. NuGet credentials can be provided with NuGet Auth task if needed.
Here is my walkaround:
I firstly published my private dotnet tool nupkg file also as an universal package to the same Azure Artifacts feed.
I was able to then use Universal Package task to download the .nupkg file into $(System.DefaultWorkingDirectory)/nupkgs/. This task will handle the authorization to Azure Artifacts feeds.
steps:
- task: UniversalPackages#0
displayName: 'Download mytool.cli.universal'
inputs:
downloadDirectory: '$(System.DefaultWorkingDirectory)/nupkgs/'
vstsFeed: '63d4aa2f-3ae7-4c27-8c18-aa8e3a9ff353'
vstsFeedPackage: '916d9a27-2c07-4071-8631-377f2ac08ed7'
vstsPackageVersion: 0.2.0
I then had the DotNetCoreCLI task to install my nupkg locally in agents.
steps:
- task: DotNetCoreCLI#2
displayName: 'Install mytool as a dotnet tool'
inputs:
command: custom
custom: tool
arguments: 'install --global mytool.CLI --add-source ./nupkgs --version 0.2.0'
You need to add the nuget authenticate task before you try to access the nuget feed

setup teamcity with .core, run command fails

I am trying to migrate from Jenkins to Teamcity 2018
So far I have 4 build steps:
Dotnet restore
dotnet build
dotnet run
dotnet test
When teamcity runs 3rd step, it fails.
it tries to run :
dotnet.exe run --project .\Prime.csproj #D:\TeamCity\buildAgent\temp\agentTmp\5d23e7ecee784cabb12baefd7175c67d.rsp
and it gives error
Unhandled Exception: System.FormatException: Unrecognized argument format: '#D:\TeamCity\buildAgent\temp\agentTmp\5d23e7ecee784cabb12baefd7175c67d.rsp'.
I think, it because dotnet cli doesn't accept the # part..
Have anyone seen such error before?
Solution has 2 projects: Prime (the main code) and a tests project with all the tests. The tests project runs just with with 'dotnet test' command
Using dotnet core 2.0 .
So the only way forward which I found is to run .core app in Docker.
So, you need to publish the app to a folder and then put that code into a docker image and then set up your test project to run against docker instance of the app.

How to specifiy --project in the "dotnet run" build step

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!

Resources