Custom NuGet package produces "Could not load file or assembly System.Runtime, Version=4.2.0.0"

0

Project_A.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

</Project>  

Project_A depends on Project_B. This is what Project_B.csproj looks like (I am forced to keep it compatible with both net461 and netcoreapp2.0):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Dapper" Version="1.50.4" />
    <PackageReference Include="SharpCompress" Version="0.16.2" />
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Properties\" />
  </ItemGroup>

</Project>

If I pack Project_B as a nuget package, and then add it to Project_A, I have the following exception when running the Project_A in debug:

System.IO.FileLoadException: 'Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

None of the possible solutions listed here seem to work for me.

But if I add the exact same Project_B "by code" (as a "project" reference to Project_A), there is no error whatsoever.


These are the nuget package settings (building it with Cake):

var nugetPackageSettings = new NuGetPackSettings
{
    Id = config["packageName"],
    Version = versionNumberStr,
    Title = config["packageName"],
    Authors = new[] { "Myself },
    Owners = new[] { "TheCompany" },
    Description = "Blah blah",      
    Copyright = $"TheCompany {DateTime.Now.Year}",
    RequireLicenseAcceptance = false,
    Symbols = true,
    IncludeReferencedProjects = true,
    NoPackageAnalysis = true,
    BasePath = "./",
    Files = context.GetAllDllFiles((string[])config["dlls"], (string)config["artifactsFolder"]),
    Dependencies = context.GetAllNuSpecDependencies((string[])config["csprojs"]),
    OutputDirectory = config["tmpNugetOutputDirectory"]
};

...

settings.Add("framework", "net461");
settings.Add("packageName", "MyProject");   

...

Task("Build")
    .IsDependentOn("NuGetRestore")
    .IsDependentOn("Clean")
    .Does(() =>
    {
        // Settings:
        var framework = (string)settings["framework"];
        var configuration = (string)settings["configuration"];
        var artifactsFolder = (string)settings["artifactsFolder"];

        var targetProjectFile = (string)settings["targetProjectFile"];

        // Process:
        var dotnetCoreBuildSettings = new DotNetCoreBuildSettings()
        {
            Framework = framework,
            Configuration = configuration,
            OutputDirectory = artifactsFolder
        };
        DotNetCoreBuild(targetProjectFile, dotnetCoreBuildSettings);
    }); 
c#
msbuild
.net-core
asked on Stack Overflow Oct 5, 2018 by Xavier Peña

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0