Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet publish --no-build error MSB4018 ComputeManagedAssemblies #12803

Open
rogatec opened this issue Aug 6, 2020 · 6 comments
Open

dotnet publish --no-build error MSB4018 ComputeManagedAssemblies #12803

rogatec opened this issue Aug 6, 2020 · 6 comments
Milestone

Comments

@rogatec
Copy link

rogatec commented Aug 6, 2020

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]
@marcpopMSFT marcpopMSFT added the untriaged Request triage from a team member label Aug 12, 2020
@sfoslund
Copy link
Member

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

@sfoslund sfoslund removed the untriaged Request triage from a team member label Aug 12, 2020
@sfoslund sfoslund removed their assignment Aug 12, 2020
@sfoslund sfoslund added this to the Backlog milestone Aug 12, 2020
@rogatec
Copy link
Author

rogatec commented Aug 13, 2020

@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

@Leon99
Copy link

Leon99 commented Dec 2, 2020

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.

@cocowalla
Copy link

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.

@alexpovel
Copy link

Note that the --runtime flag to build apparently doesn't work anymore: #14281 .

@hypdeb
Copy link

hypdeb commented Oct 21, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants