MSB3277 in child project - c#

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?

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>

NU1605 Detected package downgrade error when try the Publish project

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>

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.

Wrong version of SQLitePCLRaw.core used (1.1.13 instead of 2.0.2) in Xamarin.iOS project causes build error

I have a build error in Xamarin.iOS project:
MTOUCH : error MT2101: Can't resolve the reference 'System.String SQLitePCL.raw::sqlite3_errmsg(SQLitePCL.sqlite3)', referenced from the method 'System.String SQLite.SQLite3::GetErrmsg(SQLitePCL.sqlite3)' in 'SQLitePCLRaw.core, Version=1.1.13.388, Culture=neutral, PublicKeyToken=1488e028ca7ab535'. [/Users/[Redacted]/[Redacted]/[Redacted]/src/[Redacted].iOS/[Redacted].iOS.csproj]
Higher in the build log I can see that different version of SQLitePCLRaw.core is used than the one provided in csproj, i.e.:
LinkerPleaseInclude.cs(179,25): warning CS1702: Assuming assembly reference 'SQLitePCLRaw.core, Version=2.0.1.610, Culture=neutral, PublicKeyToken=1488e028ca7ab535' used by 'SQLite-net' matches identity 'SQLitePCLRaw.core, Version=2.0.2.669, Culture=neutral, PublicKeyToken=1488e028ca7ab535' of 'SQLitePCLRaw.core', you may need to supply runtime policy [/Users/[Redacted]/[Redacted]/[Redacted]/src/[Redacted].iOS/[Redacted].iOS.csproj]
This, however, is not saying about downgrade to 1.1.13. When I don't reference this method in LinkerPleaseInclude.cs I don't get this warning at all.
In my csproj I have set:
<PackageReference Include="sqlite-net-sqlcipher">
<Version>1.7.302-beta</Version>
</PackageReference>
<PackageReference Include="akavache.sqlite3">
<Version>6.9.10</Version>
</PackageReference>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher">
<Version>2.0.2</Version>
</PackageReference>
<PackageReference Include="SQLitePCLRaw.core">
<Version>2.0.2</Version>
</PackageReference>
So even though I have explicitly set SQLitePCLRaw.core version to 2.0.2 in csproj a different version is used by the compiler. How can I supply runtime policy as stated in the warning?
The answer is as usually related to dependencies. I had to downgrade them and had to assure compatibility.
Currently I use:
<PackageReference Include="sqlite-net-sqlcipher" Version="1.6.292" />
<PackageReference Include="SQLitePCLRaw.bundle_sqlcipher" Version="1.1.13" />
<PackageReference Include="akavache.sqlite3" Version="6.5.1" />
It seems that the lowest Akavache supporting 1.1.13 of SQLitePCL is 6.5.1 and any higher even tough I've been supplying 2.0.2 was using wrong version.

.net standard, windows compatibility pack and registry

I have a .net standard 2.0 library that I want to use to access the registry via the windows compatibility pack (if the OS its running on is Windows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("On windows.");
var dropFolder = Microsoft.Win32.Registry.GetValue(keyName: $#"{userRoot}\{subkey}", valueName: "DropFolder", defaultValue: #"C:\somepath");
Console.WriteLine($"Drop folder is {dropFolder}");
}
This crashes with an exception
Managed Debugging Assistant 'BindingFailure' : 'The assembly with
display name 'Microsoft.Win32.Registry' failed to load in the 'Load'
binding context of the AppDomain with ID 1. The cause of the failure
was: System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.'
I have installed the Windows Compatibility nuget package into my .net standard project. I have also tried installing the Microsoft.Win32.Registry nuget package.
The error perists.
If I comment out the lines
var dropFolder = Microsoft.Win32.Registry.GetValue(keyName: $#"{userRoot}\{subkey}", valueName: "DropFolder", defaultValue: #"C:\somepath");
Console.WriteLine($"Drop folder is {dropFolder}");
It works fine.
I am referencing the .net standard library from a .net framework library so no option to go to .net core.
The .dot net standard cs proj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0" />
<PackageReference Include="MQTTnet" Version="2.8.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="RabbitMQ.Client" Version="5.1.0" />
</ItemGroup>
</Project>
For the missing binary to be included in the output of your .NET Framework project, you should also install the Microsoft.Windows.Compatibility package in this project. Or at least install the Microsoft.Win32.Registry package.

Categories

Resources