dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.24k stars 1.35k forks source link

Found conflicts between different versions of the same dependent assembly that could not be resolved. #2478

Open SirwanAfifi opened 7 years ago

SirwanAfifi commented 7 years ago

my project is on top of .NET Core (1.0.4). when I build solution (it consist four projects) using dotnet build command I get following warnings:

Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.

  MyProject.Domain -> /Users/sirwan/Documents/Projects/MyProject/src/MyProject.Domain/bin/Debug/netcoreapp1.1/MyProject.Domain.dll
/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/sirwan/Documents/Projects/MyProject/src/MyProject.Core/MyProject.Core.csproj]
  MyProject.Core -> /Users/sirwan/Documents/Projects/MyProject/src/MyProject.Core/bin/Debug/netcoreapp1.1/MyProject.Core.dll
/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/sirwan/Documents/Projects/MyProject/test/MyProject.Test/MyProject.Test.csproj]
  MyProject.Test -> /Users/sirwan/Documents/Projects/MyProject/test/MyProject.Test/bin/Debug/netcoreapp1.1/MyProject.Test.dll
/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/sirwan/Documents/Projects/MyProject/src/MyProject.Web/MyProject.Web.csproj]
  MyProject.Web -> /Users/sirwan/Documents/Projects/MyProject/src/MyProject.Web/bin/Debug/netcoreapp1.1/MyProject.Web.dll

Build succeeded.

/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/sirwan/Documents/Projects/MyProject/src/MyProject.Core/MyProject.Core.csproj]
/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/sirwan/Documents/Projects/MyProject/test/MyProject.Test/MyProject.Test.csproj]
/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/sirwan/Documents/Projects/MyProject/src/MyProject.Web/MyProject.Web.csproj]
    3 Warning(s)
    0 Error(s)

Time Elapsed 00:00:16.69

I am wondering how t get rid of these warning messages. any idea?

PS: Here is the csproj files: MyProject.Core:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <AssemblyName>MyProject.Core</AssemblyName>
    <PackageId>MyProject.Core</PackageId>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="../MyProject.Domain/MyProject.Domain.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="1.1.10.0" />
    <PackageReference Include="Mailjet.Api" Version="1.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Automapper" Version="5.1.1" />
    <PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.2.3" />
    <PackageReference Include="MailKit" Version="1.10.1" />
    <PackageReference Include="CsvHelper" Version="2.16.3" />
    <PackageReference Include="ImageSharp" Version="1.0.0-alpha9-00187" />
    <PackageReference Include="System.ValueTuple" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
  </ItemGroup>
</Project>

MyProject.Domain:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <DebugType>portable</DebugType>
    <AssemblyName>MyProject.Domain</AssemblyName>
    <PackageId>MyProject.Domain</PackageId>
    <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="System.ValueTuple" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <Compile Update="Models\BaseModel.cs">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Compile>
  </ItemGroup>
</Project>

MyProject.Web:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>MyProject.Web</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>MyProject.Web</PackageId>
    <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
    <PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="../MyProject.Domain/MyProject.Domain.csproj" />
    <ProjectReference Include="../MyProject.Core/MyProject.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="1.1.10.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" />
    <PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Automapper" Version="5.1.1" />
    <PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.2.3" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="System.ValueTuple" Version="4.3.1" />
  </ItemGroup>
  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="npm install" />
    <Exec Command="bower install" />
  </Target>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup>
    <Content Update="appsettings.json" CopyToPublishDirectory="Never" />
  </ItemGroup>
</Project>

MyProject.Test:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <DebugType>portable</DebugType>
    <AssemblyName>MyProject.Test</AssemblyName>
    <PackageId>MyProject.Test</PackageId>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
    <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="../../src/MyProject.Domain/MyProject.Domain.csproj" />
    <ProjectReference Include="../../src/MyProject.Core/MyProject.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
    <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
    <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
    <PackageReference Include="Automapper" Version="5.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
  </ItemGroup>
</Project>
A110SHT commented 6 years ago

any solution for this warning? i am facing in .net core 2.0.2

gusarov commented 6 years ago

+1 same here

sigmondzavion commented 5 years ago

same here

ecoffman commented 5 years ago

same here in 2.2.300

stevo-knievo commented 4 years ago

I'm facing the same issue in .NET Core 3.1.401.

/usr/local/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: Found conflicts between different versions of "Microsoft.EntityFrameworkCore" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/stefan/Development/Prototypes/dotnet-migrations-azure-functions/src/Persistence.Migrations/Persistence.Migrations.csproj]
/usr/local/share/dotnet/sdk/3.1.401/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: Found conflicts between different versions of "Microsoft.EntityFrameworkCore.Relational" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/Users/stefan/Development/Prototypes/dotnet-migrations-azure-functions/src/Persistence.Migrations/Persistence.Migrations.csproj]

If I change the package reference from

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.7">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

to

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.7" />

the warnings disappear

alexvenetis commented 4 years ago

thank you, @stevo-knievo! your solution worked for me as well

stevo-knievo commented 4 years ago

This time I solved it differently :)

I added the Microsoft.EntityFrameworkCore.Relational dependency.

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.9" />

.NET Core SDKs installed: 3.1.403

jzabroski commented 3 years ago

In my case, the problem appears to occur when a nuget package update is not fully up-to-date.

In particular, VBCSCompiler and/or MSBuild.exe lock files that prevent package restore from removing older versions of .NET Framework packages.config restores.

Another way this can occur is if you go to "Manage Packages for this Solution" and you have only one of your "Package source:" selected when you select Update. You need to make sure that when you Update packages, that you have "Package source: All" selected, like below.

image

Once your solution is messed up, there are a couple of options

  1. Reset your version control system's current working copy to undo all changes
    • You probably will want to close Visual Studio before doing this, and re-open it once done.
  2. Painful solution, described below

The painful solution is to:

  1. Close Visual Studio 2019
  2. Open Windows Task Manager and kill all instances of VBCSCompiler and MSBuild.exe (32-bit)
  3. Delete all bin directories
  4. Delete all obj directories
  5. Delete the "packages" directory where nuget restores all old-style packages

These first two steps are needed because .NET Framework locks any dll files it loads, and MSBuild.exe is a .NET Framework application. This will prevent Access to the path 'DotNetCompilerPlatformTasks.dll' is denied. errors in steps 3-5.

Steps three to five "clear the cache", as it were.

The next step is to verify that in your legacy App.config and legacy .csproj file that the References point to the right version in the old-style packages folder. Visual Studio "Find In All Files" will not find these old version numbers for some reason.