2
votes

I'm trying to build an UWP app (created with VS2017) with Cake. I'm getting several "could not load file or assembly System.Private.CoreLib...." exceptions during the build phase.

Steps to reproduce: Create UWP app named "Example" in VS2017 under ./src dir and use following cake script to build:

#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0

var target = Argument("target", "default");
var configuration = Argument("configuration", "Release");

var buildDir = Directory("./src/Example/bin") + Directory(configuration);

Task("Clean")
    .Does(() =>
{
    CleanDirectory(buildDir);
});

Task("Restore-NuGet-Packages")
    .IsDependentOn("Clean")
    .Does(() =>
{
    NuGetRestore("./src/Example.sln");
});

Task("Build")
    .IsDependentOn("Restore-NuGet-Packages")
    .Does(() =>
{
    if(IsRunningOnWindows())
    {
       MSBuild("./src/Example.sln", settings =>
         settings.SetConfiguration(configuration));
    }
});

Task("Default")
     .IsDependentOn("Build");

RunTarget(target);

//Update:

first few log statements in the build phase:

Executing task: Build
Executing: "C:/Program Files (x86)/Microsoft Visual 
Studio/2017/Community/MSBuild/15.0/Bin/amd64/MSBuild.exe" /v:normal /p:Configuration="Release" /target:Build "C:/Users/jannik/Documents/Visual Studio 2017/Projects/example/src/Example.sln
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

the first error looks like this:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets(1254,5): error MSB3816: Loading assembly "C:\Users\jannik\.nuget\packages\runtime. Private.Uri\4.0.2\runtimes\aot\lib\netcore50\System.Private.Uri.dll" failed. System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7 r one of its dependencies. The system cannot find the file specified.\r [C:\Users\jannik\Documents\Visual Studio 2017\Projects\example\src\Example\Example.csproj]
1
If you launch Cake with diagnostic verbosity, can you see that it's using MSBuild 15.x? stackoverflow.com/a/38658796/5883153 - devlead
y it seems to use MSBuild 15 - jannikb

1 Answers

2
votes

I was able to reproduce your error. This post is what shed light the problem when I realized that MSBuild was defaulting to x64 version from the command line. I was able to use Cake DSL to get past the issue by explicitly setting the MSBuild platform to the x86 version. Below are the settings I used to get it working.

From MSDN:

Use the x86 build tools that are used by default by Visual Studio. We don't recommend using the AMD64 MSBuild tools, which are found in C:\Program Files (x86)\MSBuild\12.0\bin\amd64; these may create build problems.

Note: I explicitly set the PlatformTarget because that was the very next build error I encountered.

settings .WithTarget("Publish") .SetVerbosity(Verbosity.Minimal) .UseToolVersion(MSBuildToolVersion.VS2017) .SetConfiguration(configuration) .SetMSBuildPlatform(MSBuildPlatform.x86) .SetPlatformTarget(PlatformTarget.x86) .WithProperty("AppxBundle","Always") .WithProperty("AppxBundlePlatforms","x86"))