sdk icon indicating copy to clipboard operation
sdk copied to clipboard

dotnet publish --no-build error MSB4018 ComputeManagedAssemblies

Open rogatec opened this issue 5 years ago • 5 comments

Hi,

regarding to the issue #9552 I am encountering the following error:

I am trying to publish a dotnet core 3.1. cli with a project reference to a netstandard2.0 library.

Steps to reproduce

I created a sample .net core 3.1 console app which I've uploaded, so you can reproduce the issue.

https://github.com/rogatec/Dotnet31ConsoleApp

  1. clone the project
  2. Within the root folder execute the following
    • dotnet restore
    • dotnet build --no-restore -c Release
    • dotnet test --no-build -c Release
    • dotnet publish "Dotnet31ConsoleApp/Dotnet31ConsoleApp.csproj" --no-build -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:ReadyToRun=true -p:ReadyToRunShowWarnings=true -p:Version=1.0 -o publish/win

Do not use VS publish option. If so delete the file from bin folder

Expected behavior

The project is successfully published in the given output path "publish/win".

Actual behavior

I am getting the following error stack trace:

Microsoft (R)-Build-Engine, Version 16.6.0+5ff7b0c9e für .NET Core
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018: Unerwarteter Fehler bei der ComputeManagedAssemblies-Aufgabe. [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018: System.IO.FileNotFoundException: Could not find file 'D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\obj\Release\netcoreapp3.1\win-x64\Dotnet31ConsoleApp.dll'. [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018: File name: 'D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\obj\Release\netcoreapp3.1\win-x64\Dotnet31ConsoleApp.dll' [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Mono.Cecil.ModuleDefinition.GetFileStream(String fileName, FileMode mode, FileAccess access, FileShare share) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Utils.IsManagedAssembly(String fileName) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at ILLink.Tasks.ComputeManagedAssemblies.<>c.<Execute>b__8_0(ITaskItem f) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.Linq.Enumerable.WhereArrayIterator`1.ToArray() [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at ILLink.Tasks.ComputeManagedAssemblies.Execute() [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]

Environment data

dotnet --info output:

λ dotnet --info .NET Core SDK (gemäß "global.json"): Version: 3.1.302 Commit: 41faccf259

Laufzeitumgebung: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.302\

Host (useful for support): Version: 3.1.6 Commit: 3acd9b0cd1

.NET Core SDKs installed: 3.1.301 [C:\Program Files\dotnet\sdk] 3.1.302 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Additional information

I used all those fancy new options, but with just dotnet publish "Dotnet31ConsoleApp/Dotnet31ConsoleApp.csproj" --no-build -c Release -r win-x64 I am receiving the following error output:

Microsoft (R)-Build-Engine, Version 16.6.0+5ff7b0c9e für .NET Core
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(147,5): error MSB3030: Datei "D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\bin\Release\netcoreapp3.1\win-x64\Dotnet31ConsoleApp.runtimeconfig.json" konnte nicht kopiert werden, da die Datei nicht gefunden wurde. [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(147,5): error MSB3030: Datei "obj\Release\netcoreapp3.1\win-x64\Dotnet31ConsoleApp.dll" konnte nicht kopiert werden, da die Datei nicht gefunden wurde. [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(147,5): error MSB3030: Datei "D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\bin\Release\netcoreapp3.1\win-x64\Dotnet31ConsoleApp.deps.json" konnte nicht kopiert werden, da die Datei nicht gefunden wurde. [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(147,5): error MSB3030: Datei "obj\Release\netcoreapp3.1\win-x64\Dotnet31ConsoleApp.pdb" konnte nicht kopiert werden, da die Datei nicht gefunden wurde. [D:\_Entwicklung\tmp\Dotnet31ConsoleApp\Dotnet31ConsoleApp\Dotnet31ConsoleApp.csproj]

rogatec avatar Aug 06 '20 12:08 rogatec

@rogatec thanks for filing an issue, do you mind providing a binlog for the failure?

sfoslund avatar Aug 12 '20 18:08 sfoslund

@sfoslund I added the /bl parameter to my publish command and it created the binlog added to this comment. Sorry for not providing it in the first place. msbuild.zip

rogatec avatar Aug 13 '20 06:08 rogatec

I had the same issue, both locally and in ADO pipeline with vmImage: 'windows-latest'. Publishing with --no-build tried to locate existing binaries in a wrong location - without the platform subfolder (e.g. x86), which dotnet build creates. Adding /p:Platform=x86 to dotnet publish command line helped. I reckon this should be (at least) documented somewhere as it must be a common scenario.

Leon99 avatar Dec 02 '20 00:12 Leon99

I'm having the same problem after upgrading from netcoreapp3.1 to net5.0, so for example this doesn't work:

dotnet build
dotnet publish --no-build --self-contained --runtime win-x64

C:\Program Files\dotnet\sdk\5.0.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(225,5): error MSB4018: The "ComputeManagedAssemblies" task failed unexpectedly. [C:\Acme\Acme.csproj]
C:\Program Files\dotnet\sdk\5.0.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(225,5): error MSB4018: System.IO.FileNotFoundException: Could not find file 'C:\Acme\obj\Release\net5.0\win-x64\Acme.dll'. [C:\Acme\Acme.csproj]
C:\Program Files\dotnet\sdk\5.0.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(225,5): error MSB4018: File name: 'C:\Acme\obj\Release\net5.0\win-x64\Acme.dll' [C:\Acme\Acme.csproj]
C:\Program Files\dotnet\sdk\5.0.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(225,5): error MSB4018:    at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) [C:\Acme\Acme.csproj]
...

Strangely, I noticed that it works as expected if when using dotnet build I explicitly specify the runtime, e.g. this works:

dotnet build --runtime win-x64
dotnet publish --no-build --self-contained --runtime win-x64

And this is when I noticed the publish task is looking for files in a runtime-specific folder, which presumably it wasn't doing for .NET Core 3.1.

cocowalla avatar Mar 28 '21 20:03 cocowalla

Note that the --runtime flag to build apparently doesn't work anymore: https://github.com/dotnet/sdk/issues/14281 .

alexpovel avatar Aug 11 '22 11:08 alexpovel

I have a similar, maybe related issue. I have native dependencies such as MKL. I run the following:

dotnet restore
dotnet build --configuration Release --no-restore
dotnet publish MyProject.csproj --no-build --configuration Release

This results in the runtimes folder to contain the native dependencies for all the possible runtimes. The resulting artifacts are in my case 6 times bigger than they should be because of that.

what I would like to do is run

dotnet restore
dotnet build --configuration Release --no-restore
dotnet publish MyProject/MyProject.csproj --no-build --configuration Release --runtime linux-x64

But it fails with

C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(680,7): error : Manifest file at 'obj\Release\net6.0\linux-x64\stat
icwebassets.build.json' not found. [C:\repos\my-project\service\MyProject\MyProject.csproj]

I'm not even sure why it's using a Razor target to begin with as my project is a gRPC service and should have nothing to do with Razor. But I guess that's another topic.

Maybe the runtime thing is not what I'm looking for. I would be okay with any other solution which allows me to not have ios dependencies in my Linux container :D

hypdeb avatar Oct 21 '22 11:10 hypdeb