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

build fails when targeting netcoreapp3.1 and net5.0 #13359

Closed
stefanloerwald opened this issue Sep 3, 2020 · 3 comments
Closed

build fails when targeting netcoreapp3.1 and net5.0 #13359

stefanloerwald opened this issue Sep 3, 2020 · 3 comments

Comments

@stefanloerwald
Copy link

This is an ugly one for people upgrading from netcoreapp3.1 to net5.0..

The setup:

  • An empty (no .cs files) class library project. Full csproj at path ClassLibrary1\ClassLibrary1.csproj:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
  </PropertyGroup>

</Project>
  • A minimalistic test project (same: no .cs files). Full csproj at path NUnitTestProject1/NUnitTestProject1.csproj:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net5.0</TargetFrameworks>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
  </ItemGroup>

</Project>

(Side note: the path suggests NUnit, but the reference was removed, as that's not the root of the issue at all.)

Now the build process:

FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster
COPY . .
RUN dotnet test NUnitTestProject1/NUnitTestProject1.csproj
RUN dotnet build -c Release -o /app/build

The build will fail on the last command. The error log is:

2020-09-03T08:00:50.5307809Z Step 4/4 : RUN dotnet build -c Release -o /app/build
2020-09-03T08:00:50.5496428Z  ---> Running in afaf6729f4fa
2020-09-03T08:00:51.2819871Z Microsoft (R) Build Engine version 16.7.0-preview-20360-03+188921e2f for .NET
2020-09-03T08:00:51.2820120Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-09-03T08:00:51.2820238Z 
2020-09-03T08:00:53.0044398Z   Determining projects to restore...
2020-09-03T08:00:53.5041025Z   All projects are up-to-date for restore.
2020-09-03T08:00:53.6243808Z   You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
2020-09-03T08:00:53.6244559Z   You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
2020-09-03T08:00:54.8928782Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8929578Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018: System.IO.IOException: The process cannot access the file '/app/build/ClassLibrary1.deps.json' because it is being used by another process. [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8935929Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.FileStream.Init(FileMode mode, FileShare share, String originalPath) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8936631Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8943017Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8943612Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.File.Create(String path) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8944220Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8948105Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore() [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8948685Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8952595Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8956187Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:54.8989765Z   ClassLibrary1 -> /app/build/ClassLibrary1.dll
2020-09-03T08:00:55.0730864Z   NUnitTestProject1 -> /app/build/NUnitTestProject1.dll
2020-09-03T08:00:55.0949798Z 
2020-09-03T08:00:55.0950154Z Build FAILED.
2020-09-03T08:00:55.0955028Z 
2020-09-03T08:00:55.0960284Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0978113Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018: System.IO.IOException: The process cannot access the file '/app/build/ClassLibrary1.deps.json' because it is being used by another process. [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0982645Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.FileStream.Init(FileMode mode, FileShare share, String originalPath) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0987064Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0992692Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0993265Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at System.IO.File.Create(String path) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0998724Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.0999330Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore() [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.1006812Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.1007449Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.1008224Z /usr/share/dotnet/sdk/5.0.100-preview.7.20366.15/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(195,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/ClassLibrary1/ClassLibrary1.csproj]
2020-09-03T08:00:55.1008446Z     0 Warning(s)
2020-09-03T08:00:55.1008574Z     1 Error(s)
2020-09-03T08:00:55.1008644Z 
2020-09-03T08:00:55.1008769Z Time Elapsed 00:00:03.68
2020-09-03T08:00:55.2952741Z The command '/bin/sh -c dotnet build -c Release -o /app/build' returned a non-zero code: 1
2020-09-03T08:00:55.2960996Z ##[error]Process completed with exit code 1.

A solution (to those who can just break with the past...) is to remove the reference to netcoreapp3.1.

A full repo showing the issue is available here: https://github.com/stefanloerwald/dotnet-build-targetframeworks-bug. It includes a github action to demonstrate that the issue does not just exist on my machine.

@dsplaisted
Copy link
Member

The problem is you're using the -o command line option on a multi-targeted project. So it's trying to build the output for both target frameworks to the same folder, which is causing errors.

I've filed #13369 for us to improve this.

@stefanloerwald
Copy link
Author

So why does it work when not executing the test?

@Zastai
Copy link

Zastai commented Sep 14, 2020

Because then the parallel builds just overwrite the files silently. Running the tests means that the files are in use, so the overwrite can't happen.

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

3 participants