msbuild: Internal MSBuild Error: Unexpected CopyLocal flag

Steps to reproduce

See original discussion on https://github.com/dotnet/cli/issues/10452.

Using a preview 1 .NET Core SDK (3.0.100-preview-009812) with MSBuild version 16.0.225.48734 on macOS or Linux:

dotnet new console
dotnet add package akka.multinodetestrunner
dotnet build

Expected behavior

The project builds successfully, but warns for each unexpected native assembly without managed metadata found in lib/netcoreapp1.1.

Actual behavior

The project fails with the following error:

/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly. [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Unexpected CopyLocal flag. [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.CopyLocalStateUtility.IsCopyLocal(CopyLocalState state) [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.LogResults(ReferenceTable dependencyTable, List`1 idealAssemblyRemappings, List`1 idealAssemblyRemappingsIdentities, ArrayList generalResolutionExceptions) [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, GetAssemblyPathInGac getAssemblyPathInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader) [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute() [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/Users/peterhuene/tmp/repro/repro.csproj]

Note that the referenced package has incorrectly been packaged. It contains native PEs in lib/netcorelib1.1, which we do get warnings for:

/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. Assembly file '/Users/peterhuene/.nuget/packages/akka.multinodetestrunner/1.3.11/lib/netcoreapp1.1/API-MS-Win-Base-Util-L1-1-0.dll' could not be opened -- PE image doesn't contain managed metadata. [/Users/peterhuene/tmp/repro/repro.csproj]
...

The expected behavior then would provide these warnings but RAR should ignore them entirely for both referencing and copy-local.

Environment data

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview-009812
 Commit:    e3abf6e935

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.0.100-preview-009812/

Host (useful for support):
  Version: 3.0.0-preview-27122-01
  Commit:  00c5c8bc40

.NET Core SDKs installed:
  2.1.302 [/usr/local/share/dotnet/sdk]
  2.1.502 [/usr/local/share/dotnet/sdk]
  2.2.101 [/usr/local/share/dotnet/sdk]
  3.0.100-preview-009812 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview-18579-0056 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview-27122-01 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
dotnet msbuild /version
Microsoft (R) Build Engine version 16.0.225-preview+g5ebeba52a1 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

16.0.225.48734

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 16 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I have found the reason why it happens for us. The NuGet packs a certain Asp.Net Core with all of its dependencies using a NuSpec file. It packs both the platform dependent executable and the .Net Core DLL. The presences of both seems to kill msbuild. Once we excluded the EXE from the package file it worked.

Okay! I figured it out… but it might be specific to my case:

I made this change in the .csproj file where I am referencing the internal nuget package: I changed from this:

    <PackageReference Include="Microsoft.Omex.CodeGenerators.SettingsGenerator" Version="20.4.10820.11105" />

to this:

    <PackageReference Include="Microsoft.Omex.CodeGenerators.SettingsGenerator" Version="20.4.10820.11105">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

Thanks @MarkKharitonov - It is definitely this issue with both being packed.

image

This is a problem in my particular situation - EF can only generate SQL scripts from a startup exe, that is why the datacontext sits in that full fat web project.

For anyone else who comes across this - ensure that in the project properties => package, you have not checked Generate NuGet package on build.

image

If you are using the devops NuGet Pack Task, you will need create a basic .nuspec file which needs to exclusively executed (as opposed to allowing the Task to pack from the .csproj file) in order to exclude the exe

In the nuspec file, just include a package sibling section for file(s) to include and exclude such as the following:

image