How to fix NU1212 for dotnet tool install - c#

I am building a dotnet core tool and I am having trouble installing it globally. I can replicate the problem I am having but don't know how to fix it. Below are my steps
dotnet new console -o testconsole
Modify testconsole.csproj to include <PackAsTool> and <PackageOutputPath>
testconsole.csproj
dotnet restore testconsole.csproj
dotnet build testconsole.csproj
dotnet pack testconsole.csproj
dotnet tool install -g -v d --add-source ./nupkg testconsole
When installing I receive the below error
error NU1212: Invalid project-package combination for TestConsole 1.0.9. DotnetToolReference project style can only contain references of the DotnetTool type
install error
Here is a copy of testconsole.nuspec from the nupkg that includes
<packageType name="DotnetTool" /> per the suggestion from https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/
testconsole.nupsec

After finding the root cause, this error is hilarious, but also an indication of systematic issue.
Do you see this part of the warning in your output?
Package 'TestConsole 1.0.9' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project
What is this version 1.0.9? Where is .NET Framework 4.6.1 coming from? There's nothing like that in the .NET Core SDK (I looked through the sources) or under the testconsole directory on my disk.
Lets reduce the logging verbosity and re-run out install command:
$ dotnet tool install -g -v n --add-source ./nupkg testconsole
Build started 2018-09-26 7:16:47 p.m..
1>Project "/tmp/q2whkgqf.tbt/restore.csproj" on node 1 (Restore target(s)).
1>Restore:
Restoring packages for /tmp/q2whkgqf.tbt/restore.csproj...
CACHE https://api.nuget.org/v3-flatcontainer/testconsole/index.json
CACHE https://api.nuget.org/v3-flatcontainer/testconsole/1.0.9/testconsole.1.0.9.nupkg
Installing TestConsole 1.0.9.0.
Look at the last few lines carefully. dotnet tool install is trying to install https://www.nuget.org/packages/TestConsole/. Not your local testconsole nuget package!
You can work around it in a couple of ways:
Give your tools a really unique name that doesn't clash with anything on nuget.org or in your organization's nuget feed.
Add a nuget.config that <clear/>s the nuget feeds so only the ./nupkg directory is used as feed when looking to install testconsole.

Building on Omair's answer, the practical steps to solving this problem:
1. Create disable_nuget.config to disable reading from the global feed
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
</configuration>
note: give it a special name so that it doesn't get picked up by nuget by accident when you don't want it to
2. Install the tool referencing the special nuget configuration
dotnet pack
dotnet tool install --global --configfile disable_nuget.config --add-source ./nupkg TestConsole

Related

MSB3474: The task “SGen” is not supported on the .NET Core ver sion of MSBuild. Use the Microsoft XML Serializer Generator package instead

Step :1
Code:
dotnet build E:\abc.csproj /p:Platform=ANYCPU /p:Configuration=Release
.
Error:
C:\Program Files\dotnet\sdk\5.0.202\Microsoft.Common.CurrentVersion.targets(3624,5): error MSB3474: The tas
k "SGen" is not supported on the .NET Core version of MSBuild. Use the Microsoft XML Serializer Generator p
ackage instead. See https://go.microsoft.com/fwlink/?linkid=858594 for more information. [E:\abc.csproj]
Step:2 I had applied the below solution but didn't work.
Command:dotnet add E:\abc.csproj package Microsoft.XmlSerializer.Generator -v 1.0.0
I had read a document and implement a solution but the solution has some issues. sp command: 'dotnet add E:\abc.csproj package Microsoft.XmlSerializer.Generator -v 1.0.0' Error: Determining projects to restore... Writing C:\Users\AppData\Local\Temp\tmpF1E.tmp info : Adding PackageReference for package 'Microsoft.XmlSerializer.Generator' into project 'E:\abc.csproj'. error: Error while adding package 'Microsoft.XmlSerializer.Generator' to project 'E:\abc.csproj'. The project does not support adding package references through the add package command.
https://go.microsoft.com/fwlink/?linkid=858594
Remove this line from the csproj file:
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>

Add-Migration Error in Entity Framework Core

I am following Julie Lerman's Getting Started with Entity Framework Core 2.0 tutorial. I have installed Microsoft.EntityFrameworkCore.SqlServer Version 2.0.2. When I try to run add-migration initial (Package Manager Console) in VS 2017 I am obtaining the below error :
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.EntityFrameworkCore.SqlServer, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
When I run dotnet --version i get 2.1.3. Can anybody help me rectify this error.
Screenshot :
Thanks in Advance.
Following the very same Pluralsight video, I ran into this same problem. After running:
PM> install-package Microsoft.EntityFrameworkCore.SqlServer
with the default project set to SomeUI
I was able to get the add-migration initial to run without any problems at all, after doing so.
I know the following is not an exact answer to my own question. But rather than waiting to somebody answer how to solve it in VS 2017 ( Windows ) I am taking a Terminal Approach on my Mac and using dotnet cli to recreate the solution (Julie Lerman hope you won't send your favorite Samurai for a battle :P)
Note: Steps below is for Mac. Windows users having SQl Server Installed can Skip Step 1.
Step 1 : Install Docker and Pull MSSQL Image
a. Install docker and pull latest mssql image for linux using :
sudo docker pull microsoft/mssql-server-linux
b. Start the docker image using :
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=
<ComplexPassword>' -p 1433:1433 -d microsoft/mssql-server-linux
c. Optional. Install sql-cli using npm install -g sql-cli. Now you can connect to Sql Server running on Docker using mssql -s 127.0.0.1 -u sa -p.
Step 2 : Create .sln, .csproj and add references using dotnet cli
Create directory for Project and under it create a .sln file using: dotnet new sln -n SamuraiApp
Create Data and Domain class Library Projects using : dotnet new classlib -n SamuraiApp.Data and dotnet new classlib -n SamuraiApp.Domain
Create and Empty ASP.NET Core Project using dotnet new web -n SamuraiApp.UI
Add Entity Frmaework Core to Data ClassLibrary using : cd SamuraiApp.Data and dotnet add package Microsoft.EntityFrameworkCore.SqlServer
Add Entity Framework Core Design to UI Project Using : cd SamuraiApp.UI/ and dotnet add package Microsoft.EntityFrameworkCore.Design
Run dotnet restore
Step 3: Add References
Execute dotnet add SamuraiApp.Data reference SamuraiApp.Domain/SamuraiApp.Domain.csproj to add Domain as a reference to Data.
Execute dotnet add SamuraiApp.UI reference SamuraiApp.Domain/SamuraiApp.Domain.csproj to add Domain as reference to UI.
Execute dotnet add SamuraiApp.UI reference SamuraiApp.Data/SamuraiApp.Data.csproj to add Data as reference to UI.
Execute below commands to add all three projects to solution:
dotnet sln add SamuraiApp.Data/SamuraiApp.Data.csproj
dotnet sln add SamuraiApp.Domain/SamuraiApp.Domain.csproj
dotnet sln add SamuraiApp.UI/SamuraiApp.UI.csproj
Open SamuraiApp.Data.csproj in your favorite text editor and add the following:
<ItemGroup>
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
To enable dotnet ef.
Step 4 : Write Domain Classes, DataContext class and add migration
cd into SamuraiApp.Data folder and execute the below command to add initial migration:
dotnet ef migrations add Initial --startup-project ../SamuraiApp.UI
Hope it helps to somebody. But still In windows using VS 2017 I am facing issues and would hope somebody will help me solve it.
Thanks :)

ASP.NET Core WebApp not building on Travis CI

Getting the following error on TravisCI when trying to build an ASP.NET Core WebApp.
Could not find project file
/usr/lib/mono/xbuild/Microsoft/VisualStudio/v14.0/DotNet/Microsoft.DotNet.Props,
to import. Ignoring.
Builds on AppVeyor. Is there any way to install the missing file?
Note that I'm new to Travis CI so please include a reference (eg. link/step by step/guide) on how to implement your suggestion, thank you.
After trial and error we've came up with this:
Put these files into the root of your repo https://github.com/aspnet/KoreBuild/tree/1.0.0/template
Copy .travis.yml from a aspnet project e.g. https://github.com/aspnet/EntityFramework/blob/dev/.travis.yml
Remove parts you don't want, like branches and notifications
Make sure your solution and global.json is in the same directory as build.sh
I haven't found any documentation for it, so if it doesn't do what you want, you can just let it install dotnet and do what you want with commands yourself (e.g. dotnet publish)
Old answer:
If you don't solve the problem with xbuild, you can try using dotnet
cli. The install script for RTM is here:
https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.sh
Then you use dotnet restore and dotnet build (cd to directory with
project.json)
Change your .travis.yml to this:
language: csharp
install: curl -s https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.sh
| bash
script:
- dotnet restore WebApp/src/WebApp/project.json
- dotnet build WebApp/src/WebApp/project.json
addons:
apt:
packages:
- gettext
- libcurl4-openssl-dev
- libicu-dev
- libssl-dev
- libunwind8
- zlib1g
I'm not sure all of the apt packages are necessary. source:
http://andrewlock.net/adding-travis-ci-to-a-net-core-app/
It's also possible to use KoreBuild
https://github.com/aspnet/KoreBuild/tree/1.0.0/template
script: ./build.sh //Add the file to repo

NuGet install-package doesn't work. How can I get more verbose information to help debug why this is failing?

A collegue is trying to install a nuget package into a simple default c# web application. It fails almost instantly.
Is there an argument I can provide to Install-Package <some nuget package> in the Visual Studio Package Manager Console to get some verbose information to help debug why the installation fails?
Error Message:
An error occurred while retrieving package metadata for '' from source 'MyGet'.
Info:
Visual Studio: V2015
NuGet extension: 3.4.4.1321
Nuget package source: MyGet
Sample NuGet.config file found in the root directory of the solution:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="MyGet" value="https://www.myget.org/F/<our package>/api/v2" />
</packageSources>
</configuration>
For myself, I can install the package fine. In fact, we have 5 packages in this MyGet public repo and I just installed 2 of the packages, just then .. when I test this out (again) before I created this SO question.
Anyone have a suggestion, please?
UPDATE
As stated above, this is using the PACKAGE MANAGER CONSOLE, not the CLI.
Using the -verbosity detailed in the PMC this is what happens..
PM> install-package xunit -verbosity detailed
Install-Package : A parameter cannot be found that matches parameter name 'verbosity'.
At line:1 char:23
+ install-package xunit -verbosity detailed
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Install-Package], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
You could try adding the -Verbose parameter to your PowerShell command.
install-package xunit -verbose
You can also try looking at the $error object to see if that has more information, such as an exception callstack.
$error.Exception.StackTrace
The above may or may not give you more information.
Looks like you are running into http://blog.myget.org/post/2016/02/21/Two-of-my-packages-are-treated-as-one-Help!.aspx. There is a 0.7.0-dev and a 0.7-dev version of the package on the feed, which NuGet treats as the same version.
The solution is to remove one of these two packages.
You can use the -Verbose switch in the PowerShell-enabled Package Manager Console to get more details.
To rule out client-connectivity issues to MyGet, can you try diagnosing client connectivity to the feed?
https://www.myget.org/F/<feedIdentifier>/api/v2
Try using Fiddler to retrieve a specific package from the feed on that user's machine using URL format:
https://www.myget.org/F/<feedIdentifier>/api/v2/package/<packageId>/<packageVersion>
If it is a private feed, you'll need to authenticate your request, e.g. using the pre-authenticated v2 endpoint:
https://www.myget.org/F/<feedId>/auth/<apiKey>/api/v2/package/<packageId>/<packageVersion>
Clearing the NuGet client's HTTP cache may also prove useful if something is corrupt in the cache. You can clear it using the NuGet commandline command:
nuget.exe locals http-cache -clear
If the package is already in local cache, then the NuGet client will resolve it from local cache instead. It may be that the package in local cache is corrupt, in which case you can use the following NuGet commandline command:
nuget.exe locals all -clear
Finally, it may also be worth looking at the nuget.config hierarchy. The most-local nuget.config will inherit config settings from higher up the chain (e.g. machine-wide settings), one of which is the <disabledPackageSources> element. To ensure this one is not acting up here, add the following to your most-local nuget.config and retry:
<disabledPackageSources>
<clear />
</disabledPackageSources>
If none of the above helps you in resolving the issue, feel free to use the nuget commandline (nuget.exe) with -verbosity detailed as it may provide more details, such as the actual HTTP requests being made.
Also, make sure you use the latest versions of the NuGet client tools (available here)

Nuget Packages Installation

I have a solution which has a two projects. In the both the projects I have packages.config file which has the list of packages that the project uses. Whenever I build the solution I'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 3.**
(replaced folder path with **)
I have installed all the packages manually using package manager console. The installation is successful. When I build the solution now i'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 1.**
I have cleared the cache of packages. Still I get this error. Not sure why the solution build is trying to install the packages.
You can try adding -verbosity detailed to your command *\Tools\nuget install \packages.config -o \Packages to get detailed error message to help you investigate the cause.
This was happening in a new CI build I set up yesterday. The problem was that NuGet.exe wasn't at the specified path.
"exited with code 3." wasn't an error from NuGet.exe but from MSBuild.
If you were using TFS, be sure to include the location of the Nuget package in the Source Settings of build definition. This error can indicate it cannot access the files.

Categories