microsoft/MSBuildSdks

Can't open Microsoft.Build.NoTargets project after VS update

Closed this issue · 6 comments

After VS2019 update (16.11.18 -> 16.11.29) my Microsoft.Build.NoTargets project refuses to load.

Project is pretty simple:

<Project Sdk="Microsoft.Build.NoTargets/3.2.14">
  <ItemGroup>
    <PackageReference Include="Microsoft.Build.NoTargets" Version="3.2.14" />
  </ItemGroup>

  <PropertyGroup>
    <!-- Any target framework you want as long as its compatible with your referenced NuGet packages -->
    <TargetFramework>net462</TargetFramework>
    <Platforms>x64</Platforms>
    <!-- Do not add TargetFramework to OutputPath -->
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <!-- Do not expect pdb files to be generated (this is for fast up-to-date check) -->
    <DebugType>None</DebugType>
    <!-- Do not include files by default -->
    <EnableDefaultItems>false</EnableDefaultItems>
    <!-- Output subdir name -->
    <AngularProject>test</AngularProject>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutputPath>..\..\Bin\Debug\</OutputPath>
    <BuildCommand>ng build --no-progress --output-path $(OutputPath)$(AngularProject)\</BuildCommand>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <OutputPath>..\..\Bin\Release\</OutputPath>
    <BuildCommand>ng build --no-progress --output-path $(OutputPath)$(AngularProject)\ --prod</BuildCommand>
  </PropertyGroup>

  <ItemGroup>
    <None Include="**" Exclude="node_modules\**;$(BaseIntermediateOutputPath)\**;$(MSBuildProjectFile)" />
    
    <!-- This deals with fast up-to-date checks -->
    <UpToDateCheckBuilt Original="package-lock.json" Include="node_modules/.build" />
    
    <UpToDateCheckInput Include="@(None);$(MSBuildProjectFile)" Set="AngularFiles" />
    <UpToDateCheckOutput Include="$(OutputPath)$(AngularProject)\index.html" Set="AngularFiles" />
  </ItemGroup>

  <Target Name="InitModules" Inputs="package-lock.json" Outputs="node_modules/.build">
    <Exec Command="npm ci --no-progress --no-color" YieldDuringToolExecution="true" />
    <Exec Command="cd . &gt; node_modules/.build" />
  </Target>

  <Target Name="BuildAngular" BeforeTargets="AfterBuild" Inputs="@(None);node_modules/.build;$(MSBuildProjectFile)" Outputs="$(OutputPath)$(AngularProject)\index.html" DependsOnTargets="InitModules">
    <Exec Command="$(BuildCommand)" YieldDuringToolExecution="true" />
  </Target>

  <Target Name="CleanAngular" BeforeTargets="AfterClean">
    <RemoveDir Directories="$(OutputPath)$(AngularProject)\" />
  </Target>
</Project>

error is:
image

I've tried changing package version to latest (3.7.0), it still refuses to load with this error (in console):

error  : The project file cannot be opened. Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.

Is there any way to investigate what is wrong? Some sort of option that produces a log to look at...

jeffkl commented

I tried this by creating a simple project and it loads fine in VS:

<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>
</Project>

As soon as I specify <Platforms>x64</Platforms> it seems to have issues. NoTargets is designed for doing custom build actions like copying files around, not compiling an assembly. Can you try removing <Platforms />?

I tried almost the same project:

<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>
</Project>

It refuses to load with this (in VS 16.11.30):
image

Tried to use NoTargets v3.2.14, got this (logfile attached):
image

VsProjectFault_de2e7a8c-212d-4b2f-a143-1167b0acb807.failure.txt

It is safe to say smth is missing in my OS. Is there any way to tell with .NET SDK it is looking for?

EDIT: removing Platforms produced no effect in original project file.

jeffkl commented

That error should happen in any SDK-style project, like ones using Microsoft.NET.Sdk if MSBuild can't find the .NET SDK.

What .NET SDKs do you have installed? You can find this out by running dotnet --info from a command window.

Hmm... I am pretty sure I didn't have to install anything additional for this stuff to work in VS 16.11.18 (with NoTarget v3.2.14).

C:\>dotnet --info
'dotnet' is not recognized as an internal or external command,
operable program or batch file.

but Visual Studio Installer shows this:

image

jeffkl commented

I suspect that some update removed the ".NET SDK" because its now out of support. You'll need some version of the .NET SDK installed to load SDK-style projects. Try clicking that ".NET SDK (out of support)" box to install .NET SDK 5.0 and it should work.

You'll probably want to consider Visual Studio 2022 if possible.

you were right -- installing .NET SDK (out of support) component fixed all problems (for both versions of NoTarget). I didn't even need to mess with Platforms.

Thank you.