microsoft / MSBuildSdks

MSBuild project SDKs
MIT License
456 stars 81 forks source link

Microsoft.Build.Artifacts not working on Linux #233

Closed danjagnow closed 3 years ago

danjagnow commented 3 years ago

Microsoft.Build.Artifacts does not appear to work on Linux. I created a small sandbox project here that demonstrates the issue. If I build the project on Windows 10, it creates an artifacts folder with a NuGet package in the repository root. If I build it on Ubuntu 20.04 LTS, the project builds but does not create the folder.

jeffkl commented 3 years ago

We never had test coverage on Linux or Mac before, but I just added it and things seem to be working.

https://github.com/microsoft/MSBuildSdks/pull/234

Thank you for providing a repository to use for reproducing the issue. However, I'm not seeing the behavior you are:

jeff@JEFFKL-DEV:~/artifacts-issue$ git init
Initialized empty Git repository in /home/jeff/artifacts-issue/.git/
jeff@JEFFKL-DEV:~/artifacts-issue$ git remote add upstream https://github.com/danjagnow/artifacts-issue.git
jeff@JEFFKL-DEV:~/artifacts-issue$ git fetch upstream main
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 28 (delta 8), reused 21 (delta 5), pack-reused 0
Unpacking objects: 100% (28/28), 7.25 KiB | 66.00 KiB/s, done.
From https://github.com/danjagnow/artifacts-issue
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> upstream/main
jeff@JEFFKL-DEV:~/artifacts-issue$ git reset upstream/main --hard
HEAD is now at 62b1665 Added a link in the README.md
jeff@JEFFKL-DEV:~/artifacts-issue$ ls
ArtifactsIssue.sln  LICENSE  README.md  src
jeff@JEFFKL-DEV:~/artifacts-issue$ dotnet build --configuration Release
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/jeff/artifacts-issue/src/ArtifactsIssue/ArtifactsIssue.csproj (in 11.11 sec).
  ArtifactsIssue -> /home/jeff/artifacts-issue/src/ArtifactsIssue/bin/Release/netstandard2.0/ArtifactsIssue.dll
  Successfully created package '/home/jeff/artifacts-issue/src/ArtifactsIssue/bin/Release/ArtifactsIssue.1.0.0.nupkg'.

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:13.70
jeff@JEFFKL-DEV:~/artifacts-issue$ ls
ArtifactsIssue.sln  LICENSE  README.md  artifacts  src
jeff@JEFFKL-DEV:~/artifacts-issue$ cd artifacts/
jeff@JEFFKL-DEV:~/artifacts-issue/artifacts$ ls
ArtifactsIssue.1.0.0.nupkg

Am I doing something wrong?

jeff@JEFFKL-DEV:~/artifacts-issue/artifacts$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.103
 Commit:    9effbc8ad5

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.103/

Host (useful for support):
  Version: 5.0.3
  Commit:  eae88cc11b

.NET SDKs installed:
  5.0.103 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
danjagnow commented 3 years ago

The plot thickens... So I added a GitHub Actions build that uses a build matrix to try out some combinations. See my build.yml for details. The results are pretty interesting. It only fails for the combination of Ubuntu and SDK 5.0.201. You can see the results here, and I'll add a little picture, too:

image

jeffkl commented 3 years ago

Well that's weird, can you get more logging? Set this line to have --verbosity diagnostic

https://github.com/danjagnow/artifacts-issue/blob/fcd99024938b5e5d1a363d9e96646b1add015cca/.github/workflows/build.yml#L36

danjagnow commented 3 years ago

Well that's weird, can you get more logging? Set this line to have --verbosity diagnostic

Done. The results of that build are here.

jeffkl commented 3 years ago

Great, the logs show that the source path is different in 5.0.200:

13:41:28.018   2:6>Target "CopyArtifacts: (TargetId:196)" in file "/home/runner/.nuget/packages/microsoft.build.artifacts/2.1.6/build/Microsoft.Build.Artifacts.Common.targets" from project "/home/runner/work/artifacts-issue/artifacts-issue/src/ArtifactsIssue/ArtifactsIssue.csproj" (target "_PackAsBuildAfterTarget" depends on it):
                   Using "Robocopy" task from assembly "/home/runner/.nuget/packages/microsoft.build.artifacts/2.1.6/build/net5.0/Microsoft.Build.Artifacts.dll".
                   Task "Robocopy" (TaskId:118)
                     Task Parameter:
                         Sources=
                             bin/Release/netstandard2.0/

5.0.100

13:41:30.007   2:6>Target "CopyArtifacts: (TargetId:193)" in file "/home/runner/.nuget/packages/microsoft.build.artifacts/2.1.6/build/Microsoft.Build.Artifacts.Common.targets" from project "/home/runner/work/artifacts-issue/artifacts-issue/src/ArtifactsIssue/ArtifactsIssue.csproj" (target "_PackAsBuildAfterTarget" depends on it):
                   Using "Robocopy" task from assembly "/home/runner/.nuget/packages/microsoft.build.artifacts/2.1.6/build/net5.0/Microsoft.Build.Artifacts.dll".
                   Task "Robocopy" (TaskId:121)
                     Task Parameter:ShowErrorOnRetry=True (TaskId:121)
                     Task Parameter:
                         Sources=
                             bin/Release/

In the working case, the source path is the root of the bin/Release folder where the .nupkg is, but in the broken case its trying to copy from bin/Release/netstandard2.0 which does not contain the .nupkg.

The reason this is happening is in 5.0.200 the output path is now normalized with the correct directory separators based on the OS:

5.0.100

OutputPath = bin\Release\netstandard2.0\

5.0.200

OutputPath = bin/Release/netstandard2.0/

That trips up this line: https://github.com/microsoft/MSBuildSdks/blob/e31201f8df3e932c3807f44c183d7e2aa769278d/src/Artifacts/build/Microsoft.Build.Artifacts.targets#L25

Which is obvious because of the final value: 5.0.200

DefaultArtifactsSource = bin/Release/netstandard2.0\

5.0.100

DefaultArtifactsSource = bin/Release\

I'll submit a fix hopefully today. Thanks for reporting this.

danjagnow commented 3 years ago

I'll submit a fix hopefully today. Thanks for reporting this.

Nice! Thanks for tracking that down so quickly!

jeffkl commented 3 years ago

The fix is out in Microsoft.Build.Artifacts 2.2.0, if you have a minute can you verify that its working for you?

danjagnow commented 3 years ago

The fix is out in Microsoft.Build.Artifacts 2.2.0, if you have a minute can you verify that its working for you?

Confirmed! 🥇 The confirmation build with the updated package is here. It works with the full matrix. Thanks for turning that around so quickly!