NU1605 Detected package downgrade error when try the Publish project - c#

I'm trying to Publish my project because I will live the project. But when I try to publish my project I get NU1605 Detected package downgrade: Microsoft.EntityFrameworkCore from 2.1.14 to 2.1.1. Reference the package directly from the project to select a different version. MyTravelBlogs -> Microsoft.AspNetCore.App 2.1.25 -> Microsoft.EntityFrameworkCore (>= 2.1.14 && < 2.2.0) MyTravelBlogs -> Microsoft.EntityFrameworkCore (>= 2.1.1)
and the same error for
NU1605 Detected package downgrade: Microsoft.EntityFrameworkCore.Tools from 2.1.14 to 2.1.1. Reference the package directly from the project to select a different version. MyTravelBlogs -> Microsoft.AspNetCore.App 2.1.25 -> Microsoft.EntityFrameworkCore.Tools (>= 2.1.14 && < 2.2.0) MyTravelBlogs -> Microsoft.EntityFrameworkCore.Tools (>= 2.1.1)
Here is my csproj file
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>False</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
<WebStackScaffolding_ViewDialogWidth>600</WebStackScaffolding_ViewDialogWidth>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
<WebStackScaffolding_LayoutPageFile>~/Views/Shared/_myLayout.cshtml</WebStackScaffolding_LayoutPageFile>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
</Project>
I tried to add <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> to csproj file which people did in other questions but it doesn't work. I did not try to change versions of Nugets because I think it will create other problems about launching my project. How can I fix that and publish my project successfully? Thanks

I encountered with same issue but I recovered using this magic line. You may try in your project. Hope you get well.
<ItemGroup>
...
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.0" ExcludeAssets="all" PrivateAssets="all" />
</ItemGroup>

Related

All tests are inconclusive with the same "An assembly specified in the application dependencies manifest was not found" error when migrating to .NET 6

I'm migrating from .NET 5 and all tests are working, and finishing succesfully, until I update all .csproj files to .NET 6.0 like this:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
Afterwards all integration and unit tests show as inconclusive in Rider with the following error:
Test not run
Last runner error: Test runner agent exited unexpectedly Process /usr/share/dotnet/dotnet:138437 exited with code '140': Error: An assembly specified in the application dependencies manifest (Logging.UnitTests.deps.json) was not found: package: 'Autofac', version: '6.4.0' path: 'lib/net6.0/Autofac.dll'
--- EXCEPTION #1/3 [UnknownExitCodeException]
Message = “
Process /usr/share/dotnet/dotnet:138437 exited with code '140':
Error:
An assembly specified in the application dependencies manifest (Logging.UnitTests.deps.json) was not found:
package: 'Autofac', version: '6.4.0'
path: 'lib/net6.0/Autofac.dll'
”
I have tried updating all nuget packages, including autofac, to the latest version, tried all possible combinations with Autofac, but the error still remains. I'm on Arch linux and have all the correct dotnet sdks and runtimes.
dotnet --list-sdks
5.0.407 [/usr/share/dotnet/sdk]
6.0.102 [/usr/share/dotnet/sdk]
6.0.301 [/usr/share/dotnet/sdk]
dotnet --list-runtimes
Microsoft.AspNetCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
The application runs normally in both Run and Debug mode, it's just that all tests have stopped working. This also happens in the GitHub pipeline, any ideas?
Thank you very much in advance!
So after many hours finding a fix I tried the following:
Create a new .NET 6 test project
See if a small test without dependencies works, and it did work.
Look at the NuGet package references that were automatically added to that test project
Look at the NuGet package refences in the tests projects that were failing
Realize some were only implicitly referenced, remember how this has #$%^ me in the ^&%$ in the past
Directly reference "Microsoft.NET.Test.Sdk" and "xunit" in every test project like this:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Witness how all tests are running correctly again.
TL;DR, add the following to every test project you have:
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

MSB3277 in child project

Hello I got MSB3277 warning in child project if I reference parent project with two different dependencies.
ParentProject.csproj have:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Json.Microsoft" Version="6.0.0" />
Microsoft.EntityFrameworkCore.Design dependency:
Microsoft.EntityFrameworkCore.Relational (>= 6.0.1)
Pomelo.EntityFrameworkCore.MySql.Json.Microsoft dependency:
Microsoft.EntityFrameworkCore (>= 6.0.0)
ChildProject.csproj have:
<ProjectReference Include="ParentProject.csproj" />
Assembly resolotion goes fine in Parent project, but in Child I got:
warning MSB3277: Found conflicts between different versions of
"Microsoft.EntityFrameworkCore" that could not be resolved.
Is it a bug in dotnet?

NuGet problems after moving my Visual Studio extension from old csproj to SDK-style csproj

I've switched my Visual Studio extension from old csproj format to the new SDK-style format and hoped to get everything I need with the following package references (previously I had to reference like 100 different packages in my packages.config)
<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="3.8.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" />
<PackageReference Include="NuGet.VisualStudio" Version="5.8.0" />
However, while the extension builds within Visual Studio, I run into problems when building the extension with MSBuild (when restoring NuGet packages):
"C:\Path\MyExt\MyExtension.sln" (Build target) (1) ->
"C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj" (default target) (9) ->
C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.CoreUtility (>= 16.8.39) but Microsoft.VisualStudio.CoreUtility 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.CoreUtility 16.8.239 was resolved.
C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.CoreUtility (>= 16.8.39) but Microsoft.VisualStudio.CoreUtility 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.CoreUtility 16.8.239 was resolved.
C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Data (>= 16.8.39) but Microsoft.VisualStudio.Text.Data 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Data 16.8.239 was resolved.
C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Data (>= 16.8.39) but Microsoft.VisualStudio.Text.Data 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Data 16.8.239 was resolved.
C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Logic (>= 16.8.39) but Microsoft.VisualStudio.Text.Logic 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Logic 16.8.239 was resolved.
C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Logic (>= 16.8.39) but Microsoft.VisualStudio.Text.Logic 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Logic 16.8.239 was resolved.
Indeed, the packages are not on NuGet. Is this a problem with the Microsoft.VisualStudio.SDK package? Am I doing something wrong?
I think the issue is related the Microsoft.CodeAnalysis.EditorFeatures package itself. And you should contact with the author.
It's just that the problem is magnified by the new-sdk project and the true you set.
Actually, I faced the same issue in my side with even net core console project.
You can see this:
The nuget package has dependencies are >=16.8.39.
However, Microsoft.VisualStudio.CoreUtility does not have version 16.8.39 version but has 16.8.239. This is designed by the author. And according to the mechanism of nuget, it will install the minimum version of dependencies, but the new-sdk style project cannot automatically identify the invalid version, and this warning appears. But non-sdk style projects with packages.config will automatically install the valid version of the nuget dependencies.
So this issue is the dual influence of the design issue of the nuget package and the particularity of the new-sdk style project. It's just magnified in this case.
============================================
Workaround
To solve the issue, try these:
1) First, disable TreatWarningsAsErrors node under Project Properties-->Build
2) manually install
Microsoft.VisualStudio.CoreUtility 16.8.239
Microsoft.VisualStudio.Text.Data 16.8.239
Microsoft.VisualStudio.Text.Logic 16.8.239
nuget packages additionally to update the dependencies.
3) then enable TreatWarningsAsErrors to check.

Issue with Version Conflict detected for Microsoft.EntityFrameworkCore.Install Referance 3.1.2 in .NetCore 2.2?

I m working with N-tier architecture with .netcore 2.2
see how my project structure:
MainProject Version: how I m create the project(ASP.NET Core Web Application->Next->create->Empty(select the DropDown ASP.NET Core 2.2)
business logic project Version: how I m create the project(class library .net core)
data access project Version: how I m create the project(class library .net core)
model project Version: how I m create the project(class library .net core)
Error is:
Severity Code Description Project File Line Suppression State
Error NU1107 Version conflict detected for Microsoft.EntityFrameworkCore. Install/reference Microsoft.EntityFrameworkCore 3.1.2 directly to the project to resolve this issue.
projectname-> projectname.BusinessLogic -> projectname.DataAccess -> Microsoft.EntityFrameworkCore (>= 3.1.2)
projectname-> Microsoft.AspNetCore.App 2.2.0 -> Microsoft.EntityFrameworkCore (>= 2.2.0 && < 2.3.0). projectname
when I click on an error then this file display:
projectname.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DMEBase.BusinessLogic\DMEBase.BusinessLogic.csproj" />
<ProjectReference Include="..\DMEBase.Model\DMEBase.Model.csproj" />
</ItemGroup>
</Project>
Only 1 error is generated in my project
how to solve this issue? help
NuGet Packages ScreenShot:
Write Click On Solution then I m going to Managenugetpackages->Consolidate->No Packages Found:
Downgrade entity framework core version as compatible core framework.

UseSqlServer is missing and conflicting refrences?

Im trying to follow a Entity Framework Core video in a .NET Core 2.1 DAL class library. In the DbContext.OnCofiguring the following code is placed :
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlServer("Server*.");
}
The problem is that the UseSQLServer is missing? From this its suggested to add Microsoft.EntityFrameworkCore.SqlServer nuget. When doing this I get some version conflicts that I dont know how to solve :
Severity Code Description Project File Line Suppression State
Error CS1061 'DbContextOptionsBuilder' does not contain a definition
for 'UseSqlServer' and no accessible extension method 'UseSqlServer'
accepting a first argument of type 'DbContextOptionsBuilder' could be
found (are you missing a using directive or an assembly
reference?) DataAccessLayer
--
Severity Code Description Project File Line Suppression State
Error Package restore failed. Rolling back package changes for
'DataAccessLayer'.
--
Severity Code Description Project File Line Suppression State
Error NU1605 Detected package downgrade:
Microsoft.Extensions.Configuration from 2.2.0 to 2.1.1. Reference the
package directly from the project to select a different version.
DataAccessLayer -> Microsoft.EntityFrameworkCore.SqlServer 2.2.3 ->
Microsoft.EntityFrameworkCore.Relational 2.2.3 ->
Microsoft.EntityFrameworkCore 2.2.3 -> Microsoft.Extensions.Logging
2.2.0 -> Microsoft.Extensions.Configuration.Binder 2.2.0 -> Microsoft.Extensions.Configuration (>= 2.2.0) DataAccessLayer ->
Microsoft.Extensions.Configuration (>= 2.1.1) DataAccessLayer
--
Severity Code Description Project File Line Suppression State
Error NU1605 Detected package downgrade:
Microsoft.Extensions.DependencyInjection from 2.2.0 to 2.1.1.
Reference the package directly from the project to select a different
version. DataAccessLayer -> Microsoft.EntityFrameworkCore.SqlServer
2.2.3 -> Microsoft.EntityFrameworkCore.Relational 2.2.3 -> Microsoft.EntityFrameworkCore 2.2.3 ->
Microsoft.Extensions.DependencyInjection (>= 2.2.0) DataAccessLayer
-> Microsoft.Extensions.DependencyInjection (>= 2.1.1) DataAccessLayer
--
I suspect that the project is using a couple of nuget packages and some of them is referencing a diffrent version of another nuget or dll.
It suggest to reference a package direcly? Does this mean that I should reference a dll manually? Where do I get the dll from?
The default severity for NU1605 is warning and since you're seeing it as an error, it means that your project has opt-in'ed into treating errors as warnings.
The reason for the package downgrade is probably due to NuGet's nearest-wins rule. The only way to avoid a downgrade is to add a PackageReference to the downgraded package to your project, that way the version you select is always nearest and transient dependencies can never downgrade it.
Otherwise you stop shooting yourself in the foot by either turning off "treat all warnings as errors" and list only the specific warnings you want treated as errors. Or, add NU1605 to the list of warnings to suppress (<NoWarn> in the csproj).

Categories

Resources