We have changed from using nuget.exe pack, to dotnet pack (to get rid of the need for a .nuspec file)
We used to run this command:
nuget pack "MyComp.Shared\MyComp.Shared.csproj" -OutputDirectory c:\nugetlocal -version 2021.7.7.1149-local -symbols
And we would have no issues consuming this packed nuget in our local project during development.
Now instead we run
dotnet pack "MyComp.Shared\MyComp.Shared.csproj" -output c:\nugetlocal -version 2021.7.7.1149-local --include-symbols
However, when we consume this package we now get version downgrade errors. This didn't happen with nuget.exe packed, using the first command.
The error
Severity Code Description Project File Line Suppression State Tool
Error NU1605 Detected package downgrade: MyComp.Enums from 2021.7.7.1149-local to 2021.7.5.1317. Reference the package directly from the project to select a different version.
MyComp.Processors -> MyComp.Shared 2021.7.7.1149-local -> MyComp.Enums (>= 2021.7.7.1149-local)
MyComp.Processors -> MyComp.Enums (>= 2021.7.5.1317) MyComp.Processors C:\Users\uzzer\source\repos\MyCompp\MyComp.Processors\MyComp.Processors.csproj
The Nuget package project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PackageId>MyComp.Shared</PackageId>
<Description>MyComp.Shared</Description>
<Authors>MyComp</Authors>
<Company>MyComp</Company>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="10.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.6" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyComp.Extensions\MyComp.Extensions.csproj" />
<ProjectReference Include="..\MyComp.Enums\MyComp.Enums.csproj" />
</ItemGroup>
</Project>
The consuming project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MyComp.Enums" Version="2021.7.5.1317" />
</ItemGroup>
</Project>
EDIT: this link really helped solve the issue
To understand the issue,
You can take a .nupkg file, change the extension to .zip and then open the file. Inside is a .nuspec file.
When we packed with nuget.exe, this did not include anything in the <dependancies /> tag.
What we realized what that dotnet pack takes project references adds them to the internal .nuspec file, and version stamps them with the same version number as the project you are packing
So we need to make sure that when we build one, we build the dependencies and consume those too.
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>MyComp.Shared</id>
<version>2021.7.7.1150-local</version>
<authors>MyComp</authors>
<description>MyComp.Shared</description>
<dependencies>
<group targetFramework="net5.0">
<dependency id="MyComp.Enums" version="2021.7.7.1150-local" exclude="Build,Analyzers" />
<dependency id="FluentValidation" version="10.1.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Identity" version="2.2.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Identity.EntityFrameworkCore" version="5.0.6" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Abstractions" version="2.2.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.ViewFeatures" version="2.2.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.Identity.Core" version="5.0.6" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="5.0.6" exclude="Build,Analyzers" />
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package>
Related
Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(161, 5): Assembly location for Razor SDK Tasks was not specified.
The most likely cause is an older incompatible version of Microsoft.NET.Sdk.Razor,
or Microsoft.NET.Sdk.Web used by this project.
Please target a newer version of the .NET Core SDK.
I have the below package reference
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>LegalRegTech.Web.Public</AssemblyName>
<OutputType>Exe</OutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.1" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
By adding Microsoft.NET.Sdk.Razor still not able to resolve the issue. Tried the solution from this Assembly location for Razor SDK Tasks was not specified but still not able to solve the issue
It worked on the build server, after added this Nuget package:
Microsoft.NET.Sdk.Razor
Since I added the Net.SDK.Razor package, it builds successfully.
I had also added Microsoft.AspNetCore.Razor.Design, but only Microsoft.NET.Sdk.Razor is actually needed.
resource
How do I fix the nasty warning I'm getting when running .NET Core tests from a command line via dotnet test?
The dotnet --version returns back 3.1.101.
$ dotnet test
watch : Started
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5):
warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting
.NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically.
Otherwise, the PackageReference should be replaced with a FrameworkReference.
[C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5):
warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting
.NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically.
Otherwise, the PackageReference should be replaced with a FrameworkReference.
[C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj]
Test run for C:\github\demo\Demo\SmartHome.API.Test\bin\Debug\netcoreapp3.1\SmartHome.API.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Here's what my SmartHome.API.Test.csproj looks like.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartHome.API\SmartHome.API.csproj" />
<ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
</ItemGroup>
</Project>
And this is the SmartHome.API.csproj which seems to be the source of the issue.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
</ItemGroup>
</Project>
Changing a package dependency from Microsoft.AspNetCore.App (2.2.8) into a FrameworkReference in the SmartHome.API.csproj solved the problem for me at the cost of introducing a new one.
Initial fix
+ <ItemGroup>
+ <FrameworkReference Include="Microsoft.AspNetCore.App" />
+ </ItemGroup>
+
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.6.1" />
- <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
</ItemGroup>
New warning
I started seeing a new warning:
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\
Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(39,5):
warning NETSDK1086: A FrameworkReference for 'Microsoft.AspNetCore.App' was
included in the project. This is implicitly referenced by the .NET SDK and you
do not typically need to reference it from your project. For more information,
see https://aka.ms/sdkimplicitrefs
Final fix
...so I ended up removing the "Microsoft.AspNetCore.App" reference altogether. Now the build is warning-free!
i.e. the file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
</ItemGroup>
</Project>
Thanks a lot for the provided fix.
I deleted the reference <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" /> and my build is now warning-free too!! :)
Br,
harald
I am trying to resolve nugget packages with dotnet restore, but am getting the following error:
Unable to resolve 'Microsoft.NETCore.App (>= 2.1.0)' for '.NETCoreApp,Version=v2.1'
Here's my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.5.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Autofac.Extras.Moq" Version="4.2.0" />
<PackageReference Include="BCrypt.Net-Core" Version="1.4.0" />
<PackageReference Include="Easy.MessageHub" Version="3.2.1" />
<PackageReference Include="hangfire" Version="1.6.17" />
<PackageReference Include="Hangfire.MemoryStorage" Version="1.5.2" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0-rc1-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0-rc1-final" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0-rc1-final" />
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
</ItemGroup>
<Target Name="ApplyXdtConfigTransform" BeforeTargets="_TransformWebConfig">
<PropertyGroup>
<_SourceWebConfig>$(MSBuildThisFileDirectory)Web.config</_SourceWebConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)Web.$(Configuration).config</_XdtTransform>
<_TargetWebConfig>$(PublishDir)Web.config</_TargetWebConfig>
</PropertyGroup>
<Exec Command="dotnet transform-xdt --xml "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" Condition="Exists('$(_XdtTransform)')" />
</Target>
</Project>
I have installed dotnet-sdk-2.1.300-rc1-008673-win-x64 and I am using Visual Studio 2017 v15.2
Update your nuget.config file located in:
C:\Users\{username}\AppData\Roaming\NuGet\nuget.config
You need to add the v3 endpoint like this:
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
You can add the v3 nuget source via the dotnet cli:
dotnet nuget add source --name nuget.org https://api.nuget.org/v3/index.json
If that doesn't work, try running clearing out the local cache:
dotnet nuget locals all --clear
dotnet restore --force
Further Reading
Unable to resolve .NETCoreApp v3.1 Packages
Unable to resolve 'Microsoft.EntityFrameworkCore.SqlServer (>= 3.0.0)'
Problem was Visual Studio version.
Solution was to create MSBuildSdksPath environment variable that is pointing to dotnet\sdk{{version}}\Sdks, like on the following link https://github.com/aspnet/Announcements/issues/231
I'm trying to create an asp.net core 2.0 web api project with visual studio enterprise edition(fresh installed) and NuGet Package Manager fails at build phase of the project.
Here is the error message on visual studio
Result of dotnet restore
Any ideas about this problem?
.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="DataTransObj" />
<Folder Include="Json" />
<Folder Include="LogDepot" />
<Folder Include="FileDepot\" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.7" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.10" />
<PackageReference Include="Serilog" Version="2.7.1-dev-00950" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.1-dev-00790" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
obj/...nuget.g.targets file :
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\NETStandard.Library.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\build\netcoreapp2.0\Microsoft.NETCore.App.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\build\netcoreapp2.0\Microsoft.NETCore.App.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration.usersecrets\2.0.1\build\netstandard2.0\Microsoft.Extensions.Configuration.UserSecrets.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration.usersecrets\2.0.1\build\netstandard2.0\Microsoft.Extensions.Configuration.UserSecrets.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.3\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.3\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets')" />
<Import Project="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.all\2.0.7\build\netcoreapp2.0\Microsoft.AspNetCore.All.targets" Condition="Exists('C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.all\2.0.7\build\netcoreapp2.0\Microsoft.AspNetCore.All.targets')" />
</ImportGroup>
</Project>
Fresh installed Visual Studio NuGet package manager cannot import Microsoft.AspNetCore.All package
The default asp.net core 2.0 web api project template contains some nuget packages, which will import some .targets file. According to the error message:
"The imported project file ...Microsoft.AspNetCore.All.targets, cold
not be loaded. Root element is missing"
It seems the imported .target file is damaged in the NuGetFallbackFolder folder. Since it is a fall back folder, to resolve this issue, you can delete this package in that folder. Then when you create a new project, you will find Visual Studio will load that package from global packages folder C:\Users\<UserName>\.nuget\packages. Or you can copy this package from global folder to the NuGetFallbackFolder.
Hope this helps.
I have published a .net core 2.0 api bundle with
dotnet publish -c release
The release folder includes a bunch of DLL's that I didn't think would be required for running the application, ie, code generation packages etc.
Is there a way to optimise the release package so that these dll's aren't included?
Microsoft.CodeAnalysis.CSharp.Workspaces.dll
Microsoft.CodeAnalysis.Workspaces.dll
Microsoft.EntityFrameworkCore.Relational.Design.dll
Microsoft.EntityFrameworkCore.SqlServer.Design.dll
Microsoft.VisualStudio.Web.CodeGeneration.Contracts.dll
Microsoft.VisualStudio.Web.CodeGeneration.Core.dll
Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.dll
Microsoft.VisualStudio.Web.CodeGeneration.Templating.dll
Microsoft.VisualStudio.Web.CodeGeneration.Utils.dll
Microsoft.VisualStudio.Web.CodeGeneration.dll
Microsoft.VisualStudio.Web.CodeGenerators.Mvc.dll
NuGet.Frameworks.dll
System.Composition.AttributedModel.dll
System.Composition.Convention.dll
System.Composition.Hosting.dll
System.Composition.Runtime.dll
System.Composition.TypedParts.dll
dotnet-aspnet-codegenerator-design.dll
My csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
Yes. Install the Microsoft.Packaging.Tools.Trimming NuGet package. Then add this to your .csproj file:
<PropertyGroup>
<TrimUnusedDependencies>true</TrimUnusedDependencies>
</PropertyGroup>
Or use the /p:TrimUnusedDependencies=true flag from the command line.
dotnet build /p:TrimUnusedDependencies=true
dotnet publish /p:TrimUnusedDependencies=true
msbuild /p:TrimUnusedDependencies=true
msbuild /t:Publish /p:TrimUnusedDependencies=true
See Dependency Trimming documentation.