dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

Running msbuild from bootstrap folder after building from source doesn't build a simple netcoreapp3 project. #4994

Open OdeToCode opened 4 years ago

OdeToCode commented 4 years ago

Steps to reproduce

1) Ran build.cmd /p:CreateBootstrap=true - build was successful on the master branch. 2) Moved to a new folder and ran dotnet new console using the .NET Core 3.1.100 SDK 3) Ran dotnet [repohome]\artifacts\bin\bootstrap\netcoreapp2.1\MSBuild\MSBuild.dll TestM.csproj

Result:

Build FAILED.

"C:\temp\TestM\TestM.csproj" (default target) (1) ->
(ResolveTargetingPackAssets target) ->
  [repohome]\msbuild\artifacts\bin\bootstrap\netcoreapp2.1\MSBuild\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.NETCore.App' was not recognized [C:\temp\TestM\TestM.csproj]

Project file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

</Project>
benvillalobos commented 1 year ago

Can confirm this still fails, albeit with a different issue: error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found..

Some brief investigation notes:

The codepaths end up trying to resolve using the default resolver and using the MSBuildSDKsPath: C:\src\msbuild\artifacts\bin\MSBuild\Debug\net7.0\Sdks. That's because our buildenvironmenthelper's MSBuildSDKsPath is defaulted to its current directory + \Sdk\.

https://github.com/dotnet/msbuild/blob/d14b74d6f08ab7f2e17706359a38f8c22b569cb5/src/Build/BackEnd/Components/SdkResolution/DefaultSdkResolver.cs#L34

Looks like we'd need to special case if we're in the repo's artifacts dir, or use another sdk resolver other than default.