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 NuGet.Client even if response file is detected #3623

Merged
merged 6 commits into from
Apr 1, 2021

Conversation

Nirmal4G
Copy link
Contributor

@Nirmal4G Nirmal4G commented Sep 1, 2020

Bug

Fixes: NuGet/Home#9973
Fixes: NuGet/Home#10139
Regression: No

Fix

Details:

  • Checkout bash script files with Unix line ending (only LF) even on Windows. This makes sure that we can use the repo in WSL also.

  • MSBuild picks up response files automatically, which messes up the version logic reading from standard output. Adding -noAutoRsp to it is one solution but you have to add it to every MSBuild call to get
    uniform behavior. So, I have refactored the logic to work without needing it.

  • Also, build.sh currently downloads dotnet cli v1.0 for bootstrapping and runs MSBuild to get the dotnet cli version to build and test against. Since, v1 is out of support, the Sdk is not available to download. We
    have to update the version to 2.2, similar to what is specified in runFuncTests.sh. Because of the nature of the change in the POSIX scripts, we can no longer depend on space character for splitting the branch
    and version string in the CliBranchForTesting property in build\config.props. Instead, I have used colon : as a separator.

    For Example:

    <CliBranchForTesting Condition="'$(CliBranchForTesting)' == ''">release/5.0.2xx:5.0.202</CliBranchForTesting>

NOTE: This patch was separated from #3270.

Testing/Validation

Tests Added: No
Reason for not adding tests: Build Infra changes only
Validation: Through successful CI

@Nirmal4G Nirmal4G changed the title Hotfix/improve local build Fix issues with local builds Sep 1, 2020
@Nirmal4G Nirmal4G marked this pull request as ready for review September 1, 2020 11:08
@Nirmal4G Nirmal4G requested a review from a team as a code owner September 1, 2020 11:08
@zivkan
Copy link
Member

zivkan commented Sep 2, 2020

Given this PR depends on #3552, I'm marking this PR as draft to signal that it's not as high priority to review just yet. I spoke with @heng-liu about that PR, and it's a little bit problematic because of net5 breaking changes and CI agents not having preview VS, but we think we have a path forward before VS 16.8 goes GA.

Please mark the PR as ready to review once #3552 is merged and you rebase your changes.

@zivkan zivkan marked this pull request as draft September 2, 2020 20:28
@zivkan zivkan added the Community PRs created by someone not in the NuGet team label Sep 2, 2020
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch from 5bbe969 to dd93578 Compare September 3, 2020 06:48
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch from dd93578 to eb64f0f Compare September 5, 2020 22:01
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch 5 times, most recently from 2d2480e to 9ad4cb0 Compare September 28, 2020 11:30
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch 3 times, most recently from d4edea3 to 7d1f203 Compare October 3, 2020 10:45
@zivkan
Copy link
Member

zivkan commented Oct 3, 2020

@Nirmal4G PR #3552 was closed, because of CI infrastructure issues. Basically, we can't implement those changes until VS 16.8 goes GA, and our CI machines are updated to that version. So, we should be able to in a few weeks, but not yet.

If you can modify your branch so that it does not depend on the changes in #3552, then we can consider taking your changes. Thanks.

@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch from 7d1f203 to d4b0a73 Compare October 4, 2020 13:12
@Nirmal4G Nirmal4G marked this pull request as ready for review October 4, 2020 13:13
@Nirmal4G Nirmal4G requested a review from zivkan October 4, 2020 13:14
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch from d4b0a73 to a1228ec Compare October 4, 2020 14:18
Copy link
Member

@zivkan zivkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows jobs (unit tests and func tests) failed the "Install .NET 5.0 for build" step:

. 'C:\A\1\71\s\scripts\utils\InstallCLIforBuild.ps1'   5.0.100-rc.1.20452.10
Downloading .NET SDK Install Script
Channel is : 5.0.100-rc.1.20452.10 latest
##[error]Invoke-RestMethod : BlobNotFoundThe specified blob does not exist.
RequestId:ce54500d-501e-007f-035a-9a36f9000000
Time:2020-10-04T14:29:41.3924590Z
At C:\A\1\71\s\scripts\utils\InstallCLIforBuild.ps1:47 char:20
+     $versionFile = Invoke-RestMethod -Method Get -Uri $httpGetUrl
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc 
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

The version of SDK should be installed is : 
Probing folder : C:\A\1\_temp\dotnet\sdk\
C:\A\1\_temp\dotnet\dotnet-install.ps1 5.0.100-rc.1.20452.10 latest
##[error]Could not resolve version information.
At C:\A\1\_temp\dotnet\dotnet-install.ps1:323 char:9
+         throw "Could not resolve version information."
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Could not resolve version information.:String) [], RuntimeException
    + FullyQualifiedErrorId : Could not resolve version information.
 

##[error]Process completed with exit code 1 and had 2 error(s) written to the error stream.
Finishing: Install .NET 5.0 for build

On Linux, the "Install .NET 5.0 for build" step was incorrectly reported as successful, but when I look at the logs I see:

5.0.100-rc.1.20452.10
Channel is: 5.0.100-rc.1.20452.10    Version is: latest
Installing dotnet CLI into /home/vsts/work/_temp folder for building
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 34939  100 34939    0     0   109k      0 --:--:-- --:--:-- --:--:--  109k
curl: (22) The requested URL returned error: 404 The specified blob does not exist.
Add /home/vsts/work/_temp/dotnet to PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/vsts/work/_temp/dotnet
Deleting .NET Core temporary files
A compatible installed .NET Core SDK for global.json version [5.0.100-preview] from [/home/vsts/work/1/s/global.json] was not found

The CliVersionForBuilding property in config.props isn't used in build.ps1, so a successful local build won't test this. Locally, our scripts assume that the dev has installed an appropriate version themselves, and we use the system dotnet cli. On CI, we know the agents contain only GA versions of the dotnet sdk, so we have additional steps that only run on CI to get the preview SDK.

@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch 2 times, most recently from 5dd0db7 to 2a92648 Compare October 4, 2020 18:39
@zivkan
Copy link
Member

zivkan commented Oct 4, 2020

35 functional tests on Windows failed. All of them were Dotnet.Integration.Tests PackCommandTests. I'm sure they all failed for the same reason. One of them failed with this message:

Pack failed with following log information :
Microsoft (R) Build Engine version 16.7.0-preview-20360-03+188921e2f for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:\A\1\2\s.test\work\723a8b42\d2ee14af\sdk\5.0.100-preview.7.20366.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file 'C:\A\1\2\s.test\work\192d45e0\291a9f42\ClassLibrary1\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v5.0'. Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project. [C:\A\1\2\s.test\work\192d45e0\291a9f42\ClassLibrary1\ClassLibrary1.csproj]

Expected: True
Actual:   False

with this stack trace:

   at Dotnet.Integration.Test.MsbuildIntegrationTestFixture.PackProjectOrSolution(String workingDirectory, String file, String args, Boolean validateSuccess) in C:\A\1\2\s\test\NuGet.Core.FuncTests\Dotnet.Integration.Test\MsbuildIntegrationTestFixture.cs:line 273
   at Dotnet.Integration.Test.PackCommandTests.PackCommand_PackProject_OutputsBuildActionForContentFiles(String itemType, String buildAction, String expectedBuildAction) in C:\A\1\2\s\test\NuGet.Core.FuncTests\Dotnet.Integration.Test\PackCommandTests.cs:line 2655

Both Linux and Mac failed to even build the solution. The "Install .NET 5 for build" step on both have the same error message.

master:5.0.100-preview.7.20366.6
Channel is: master:5.0.100-preview.7.20366.6    Version is: latest
Installing dotnet CLI into /home/vsts/work/_temp folder for building
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 34939  100 34939    0     0  74655      0 --:--:-- --:--:-- --:--:-- 74655
curl: (22) The requested URL returned error: 404 The specified blob does not exist.
Add /home/vsts/work/_temp/dotnet to PATH

They both execute scripts/utils/InstallCLIforBuild.sh, so that script probably needs similar changes to whatever you did in InstallCLIforBuild.ps1, which is used only on Windows.

@zivkan
Copy link
Member

zivkan commented Mar 24, 2021

@Nirmal4G I rebased your PR so it includes some test fixes. Other people's PR builds are green now, but your branch has two errors.

On Mac, the log has this output:

  Discovering test assemblies for NuGet.Protocol.FuncTest
  NuGet.CommandLine.XPlat -> /Users/runner/work/1/s/artifacts/NuGet.CommandLine.XPlat/16.0/bin/Release/netcoreapp2.1/NuGet.CommandLine.XPlat.dll
  NuGet.CommandLine.Xplat.Tests -> /Users/runner/work/1/s/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/bin/Release/netcoreapp2.1/NuGet.CommandLine.Xplat.Tests.dll
  Microsoft.Build.NuGetSdkResolver -> /Users/runner/work/1/s/artifacts/Microsoft.Build.NuGetSdkResolver/16.0/bin/Release/netstandard2.0/Microsoft.Build.NuGetSdkResolver.dll
  NuGet.XPlat.FuncTest -> /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/bin/Release/netcoreapp2.1/NuGet.XPlat.FuncTest.dll
  Discovering test assemblies for NuGet.XPlat.FuncTest
MSBUILD : warning MSB1008: Only one project can be specified. [/Users/runner/work/1/s/build/build.proj]
  Switch: /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Commands.FuncTest/bin/Release/netcoreapp2.1/NuGet.Commands.FuncTest.dll
  
  For switch syntax, type "MSBuild -help"
/Users/runner/work/1/s/build/build.proj(439,5): warning MSB3073: The command "/Users/runner/work/1/s/cli/dotnet test /Users/runner/work/1/s/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/bin/Release/netcoreapp5.0/Dotnet.Integration.Test.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Commands.FuncTest/bin/Release/netcoreapp2.1/NuGet.Commands.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Commands.FuncTest/bin/Release/netcoreapp5.0/NuGet.Commands.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/bin/Release/netcoreapp2.1/NuGet.Packaging.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/bin/Release/netcoreapp5.0/NuGet.Packaging.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Protocol.FuncTest/bin/Release/netcoreapp2.1/NuGet.Protocol.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.Protocol.FuncTest/bin/Release/netcoreapp5.0/NuGet.Protocol.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/bin/Release/netcoreapp2.1/NuGet.XPlat.FuncTest.dll /Users/runner/work/1/s/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/bin/Release/netcoreapp5.0/NuGet.XPlat.FuncTest.dll --test-adapter-path:/Users/runner/work/1/s/packages/xunitxml.testlogger/2.0.0/build/_common --logger:"xunit;LogFileName=CoreFuncTests-vsts.xml" --logger:"console;verbosity=detailed" --settings:/Users/runner/work/1/s/build/xunit.runsettings" exited with code 1.
/Users/runner/work/1/s/build/build.proj(439,5): warning MSB4181: The "Exec" task returned false but did not log an error.
/Users/runner/work/1/s/build/build.proj(446,5): error : NETCore CoreFuncTests tests failed! Results: /Users/runner/work/1/s/build/TestResults/CoreFuncTests-vsts.xml
CoreFuncTests failed!!
Checking if result file exists at /Users/runner/work/1/s/scripts/funcTests/../../build/TestResults/TestResults.xml
/Users/runner/work/1/s/scripts/funcTests/../../build/TestResults/TestResults.xml not found.

I'm not 100% sure it's related to your changes, but I've also never before seen xunit discover the tests, but then not actually execute any of them.

On Linux, tests run, but 17 Dotnet.Intregration.Tests fail with this error:

System.AggregateException : One or more errors occurred. (Sequence contains more than one element) (The following constructor parameters did not have matching fixture data: MsbuildIntegrationTestFixture fixture)
---- System.InvalidOperationException : Sequence contains more than one element
---- The following constructor parameters did not have matching fixture data: MsbuildIntegrationTestFixture fixture
----- Inner Stack Trace #1 (System.InvalidOperationException) -----
   at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Dotnet.Integration.Test.MsbuildIntegrationTestFixture..ctor() in /home/vsts/work/1/s/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/MsbuildIntegrationTestFixture.cs:line 42
----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----

This class, MsbuildIntegrationTestFixture is responsible for copying the .NET SDK into a test folder, and replacing all the NuGet DLLs with the NuGet DLLs from the build. Therefore, we can test the .NET SDK with the current build of NuGet, not the version of NuGet that shipped in the .NET SDK.

As a sanity check, it makes sure that the test SDK only has a single folder in the SDK subdirectory, but for some reason there's more than one. Frankly, I have no guesses why this is happening, but this happened for at least two builds of this branch, and other people's branches are passing, so it appears related to the changes in this PR.

@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch from ed51f6f to 20ef07c Compare March 27, 2021 17:46
Adding "eol" to git attributes file for BASH script files
to always checkout with LF line endings
Fail early if the external commands encounter an error
MSBuild picks up response files automatically,
which messes up reading from standard output.

This fixes the way it's read from std output,
so that it always gets the intended value.

Also, this is just a simplified hack and in no-way
it can get the right value from any MSBuild target
output stream.
The current logic assumes there will be no multi-value
dotnet testing branches but we could be wrong...

So, to be on the safe side, It's better to match the logic
with functional tests' version.
Since the test frameworks use copied and patched cli, mismatch can cause tests fail.

One of the failures caused when sometimes "NuGetFallbackFolder" becomes the first directory
to resolve "dotnet.dll" against. It is now fixed by excluding the fallback folder in the resolving logic.
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch 3 times, most recently from 04c290b to 79fb279 Compare March 28, 2021 19:30
@Nirmal4G Nirmal4G requested a review from zivkan March 28, 2021 20:50
@zivkan
Copy link
Member

zivkan commented Mar 30, 2021

Now only tests on mac are failing.

Here's the full build logs:
mac-build-log.zip

Looks like I was wrong about running tests using the system dotnet. At 2021-03-29T23:13:24.4407250Z we see that it's running cli/dotnet test ..., and the next 3 lines are saying that command failed, but there's no output from xunit, hence it never actually ran.

At 2021-03-29T23:10:22.5364700Z, we see that the .NET SDK installed in the cli/ directory only has 2.2, there's no 5.0 SDK. That's my guess as to why the unit tests and func tests failed to run. But there's no hint as to why it failed to install the SDK defined in the build/config.props file.

I just remembered that months/years ago, I read something saying that Apple had a very old veresion of Bash on OSX, and they also changed the default shell to zsh. I don't know if our CI builds on Mac are using zsh, or bash, and if it's using bash, what version. Although you might be able to figure it out from the build logs. If your changes to runFuncTests.sh don't work on zsh, or require a new version of Bash, perhaps that's why it's failing to install the .NET 5 SDK, although it's disappointing that it's silent.

Like you, I don't have access to a Mac, at least, not until we're allowed back in the office. So, we're at the mercy of someone with a Mac testing for us. Alternatively, you could do more research into what shell Azure DevOps runs scripts on, then run the same shell in your linux/wsl install, and see if the script fails like on CI, allowing you to test locally.

Another option is to undo all your changes and just create an empty response file in the repo root. I don't know how a response file helps you manage your builds/repos, but creating an empty response file in NuGet.Client's root should prevent msbuild finding the response file outside the repo root, and be a lower complexity solution to the problem.

Copy link
Contributor Author

@Nirmal4G Nirmal4G left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to undo all your changes and just create an empty response file in the repo root.

This doesn't work. It doesn't matter where the response file is but as long as there's one that MSBuild can find and load, it displays that message and fails to get the version from the GetCliBranchForTesting target.

There should be a better way to get values from MSBuild targets.

Bash on macOS is v3.2 but only v4.3+ supports negative indexing.

This caused the script skipping the .NET SDK install for to be used with .NET CLI integration tests,
which in-turn caused the build to fail. This is a verified workaround that works on Bash versions < v4.3
@Nirmal4G Nirmal4G force-pushed the hotfix/improve-local-build branch 2 times, most recently from 0744a8a to 2070d4e Compare March 30, 2021 16:35
@zivkan
Copy link
Member

zivkan commented Mar 30, 2021

This doesn't work. It doesn't matter where the response file is but as long as there's one that MSBuild can find and load, it displays that message and fails to get the version from the GetCliBranchForTesting target.

What output? When I tested myself I didn't see any extra output, and looking at MSBuild's source code, I only see extra output at diagnostic verbosity, not minimal verbosity: https://github.com/dotnet/msbuild/blob/1629921c2b537d4452ff238981bd18519b8f5230/src/MSBuild/XMake.cs#L2316-L2319

@Nirmal4G
Copy link
Contributor Author

I looked at the source too. I don't know why or how but this is how, it outputs for me…!

nuget-client > msbuild build\config.props -nologo -v:q -t:GetCliBranchForTesting

Some command line switches were read from the auto-response file "MSBuild.rsp". To disable this file, use the "-noAutoResponse" switch.
D:\Apps\Tools\MSBuild\Current\Bin\msbuild.exe -nologo -bl -t:GetCliBranchForTesting -v:q build\config.props
nuget-client > msbuild build\config.props -nologo -v:m -t:GetCliBranchForTesting

Some command line switches were read from the auto-response file "MSBuild.rsp". To disable this file, use the "-noAutoResponse" switch.
D:\Apps\Tools\MSBuild\Current\Bin\msbuild.exe -nologo -bl -t:GetCliBranchForTesting -v:m build\config.props
  release/5.0.2xx 5.0.200-servicing.21120.4
nuget-client > msbuild build\config.props -nologo -v:n -t:GetCliBranchForTesting

Some command line switches were read from the auto-response file "MSBuild.rsp". To disable this file, use the "-noAutoResponse" switch.
D:\Apps\Tools\MSBuild\Current\Bin\msbuild.exe -nologo -bl -t:GetCliBranchForTesting -v:n build\config.props
Build started 31-03-2021 12:06:45 AM.
Project "E:\Projects\Microsoft.NET\nuget-client\build\config.props" on node 1 (GetCliBranchForTesting target(s)).
GetCliBranchForTesting:
  release/5.0.2xx 5.0.200-servicing.21120.4
Done Building Project "E:\Projects\Microsoft.NET\nuget-client\build\config.props" (GetCliBranchForTesting target(s)).

•••

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

Time Elapsed 00:00:00.09

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Apr 1, 2021

Finally, All ✔️. 🥳

@zivkan zivkan changed the title Fix issues with local builds Build NuGet.Client even if response file is detected Apr 1, 2021
@zivkan zivkan merged commit 10fcc61 into NuGet:dev Apr 1, 2021
@Nirmal4G Nirmal4G deleted the hotfix/improve-local-build branch April 1, 2021 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PRs created by someone not in the NuGet team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NuGet.Client build.sh is broken Local Build fails when Build encounters an RSP (response) file
3 participants