I am on Ubuntu 22.04 and have following sdks installed
$ dotnet --list-sdks
6.0.405 [/usr/share/dotnet/sdk]
7.0.102 [/usr/share/dotnet/sdk]
When I try to create a new Web API project I get an error
$ dotnet new webapi -f net7.0
The template "ASP.NET Core Web API" was created successfully.
Processing post-creation actions...
Restoring /home/dxxxx/dev/play/webapi7.0/webapi7.0.csproj:
Determining projects to restore...
/usr/share/dotnet/sdk/7.0.102/NuGet.targets(676,5): error : An item with the same key has already been added. Key: add [/home/dxxxx/dev/play/webapi7.0/webapi7.0.csproj]
Restore failed.
Post action failed.
Manual instructions: Run 'dotnet restore'
$
Related
I am trying to create a GitHub workflow that will run an Entity Framework Core migration on my database.
The C# project containing my data model is targeting netcoreapp3.1.
Here is the bulk of the workflow: (trigger conditions omitted)
jobs:
migrate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.1.301
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Install EF Core tools
run: |
dotnet tool install --global dotnet-ef
dotnet tool restore
- name: Migrate
run: dotnet ef database update
When the workflow runs, I get this error:
Run dotnet ef database update
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '1.0.0' was not found.
- The following frameworks were found:
3.1.5 at [/opt/hostedtoolcache/dncs/3.1.301/x64/shared/Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=1.0.0&arch=x64&rid=ubuntu.18.04-x64
##[error]Process completed with exit code 150.
I have also tried specifying the version when installing the EF Core tools (--version 3.1.0) but this doesn't change anything.
Why I am getting this error? How can I fix it?
Update:
I added a task to the workflow with these commands, right before the failing migration task:
dotnet --list-sdks
dotnet tool list --global
Output of dotnet --list-sdks:
3.1.301 [/opt/hostedtoolcache/dncs/3.1.301/x64/sdk]
Output of dotnet tool list --global:
Package Id Version Commands
--------------------------------------
dotnet-ef 3.1.6 dotnet-ef
What is looking for .NET Core 1.0.0?
I got this to work by replacing dotnet ef with dotnet-ef on the last line of the example. I also noticed that the dotnet-ef will restore and build, so some steps in the workflow are redundant.
I'm trying the following command for my .NET Core 3.1. Console application in the folder D:\core:
D:\core>dotnet publish -c Release –r ubuntu-x64 --self-contained true
And it gives an error:
MSBUILD : error MSB1008: Only one project can be specified. Switch:
ubuntu-x64
For switch syntax, type "MSBuild -help"
When I use these two commands separately they work perfectly fine, but I need Release for Ubuntu; when I don't try to specify Release for Ubuntu it creates Publish folder in Debug folder:
D:\core>dotnet publish –r ubuntu-x64 --self-contained true
D:\core>dotnet publish -c Release
To summarize, the problem is that I can't currently publish for Release for a specified OS.
You have a –r in your command. That's a em-dash (–) followed by an r. Have you tried using a normal dash/hyphen?
That works for me:
$ dotnet new console
Getting ready...
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on /home/omajid/temp/HelloWorld/HelloWorld.csproj...
Determining projects to restore...
Restored /home/omajid/temp/HelloWorld/HelloWorld.csproj (in 66 ms).
Restore succeeded.
$ dotnet publish -c Release -r ubuntu-x64 --self-contained true
Microsoft (R) Build Engine version 16.7.0-preview-20220-01+80e487bff for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored /home/omajid/temp/HelloWorld/HelloWorld.csproj (in 16.86 sec).
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
HelloWorld -> /home/omajid/temp/HelloWorld/bin/Release/net5.0/ubuntu-x64/HelloWorld.dll
HelloWorld -> /home/omajid/temp/HelloWorld/bin/Release/net5.0/ubuntu-x64/publish/
Aside: you should use the linux-x64 runtime id rather than ubuntu-x64. linux-x64 is compatible with Ubuntu, but also many other distributions too.
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
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've create a simple console application along with a simple docfx project. When I run the DocFX command to generate the documentation I get the following metadata warning and becuasue the warning leads to the documentation not being generated.
[18-06-05 05:52:41.715]Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'E:\Files\tmp\docx\docfx_project\src\src.csproj' with message: C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets: (198, 5): Error loading lock file 'E:\Files\tmp\docx\docfx_project\src\obj\project.assets.json' : Object reference not set to an instance of an object.
later in the output you see
[18-06-05 05:52:42.467]Warning:[MetadataCommand.ExtractMetadata]No metadata is generated for src.
Anyone else run into this problem? How can I get metadata to generate?
To recreate the project is pretty simple:
goto dotnet cli tools command line
docfx init
cd src
dotnet new console
cd ..
docfx
I have installed and using the dotnet sdk 2.1.300
With .net 2.1 there is a breaking change in the use of tools, which are now installed and used globally like this:
dotnet watch
dotnet user-secrets
dotnet sql-cache
dotnet dev-certs
The developers of docfx are currently working on a version which supports .net 2.1 (docfx v3): https://github.com/dotnet/docfx/pull/2829
Here you can see the current status of implemenation: https://github.com/dotnet/docfx/projects/1
So the answer to your question is: as of yet you can't use docfx with .net 2.1