Fix: WinUI Preview 2 with Visual Studio 2019 Error Creating Project

If you’ve recently upgraded to the latest Visual Studio preview (Preview 2 of VS 16.8) then you may run into issues if you attempt to create a new WinUI for Desktop project. You’ll see a prompt similar to the following and only the packaging project will get created. The full text from the error is … Continue reading “Fix: WinUI Preview 2 with Visual Studio 2019 Error Creating Project”

If you’ve recently upgraded to the latest Visual Studio preview (Preview 2 of VS 16.8) then you may run into issues if you attempt to create a new WinUI for Desktop project. You’ll see a prompt similar to the following and only the packaging project will get created.

The full text from the error is as follows.

-------------------------
Microsoft Visual Studio
-------------------------
A problem was encountered creating the sub project 'MasterDetail.Desktop'. The expression "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('', 10.0.18362.0)" cannot be evaluated. Parameter "targetPlatformIdentifier" cannot have zero length. C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets

The solution to this issue has been covered over at this github issue. The main steps are:

  • Download and extract Install-Dotnet script
  • Open an elevated command or powershell terminal window and run Install-DotNet -version 5.0.100-preview.5.20279.10
  • Open Visual Studio and create an empty solution

Note: If you attempt to simply create a new solution using the Blank App template, you’ll see the same error as before. You need to have the global.json file in the root folder before the WinUI project is created.

  • Add global.json file with the following content to the root folder of the solution (the same folder as the .sln file):
{
  "sdk": {
    "version": "5.0.100-preview.5.20279.10"
  }
}
  • Add project using the “Blank App, Packaged (WinUI in Desktop)” template

At this point you’ll be thinking to yourself that everything is looking good and you’ve successfully created your WinUI project. Unfortunately, when you go to run your project you’ll see an error similar to.

Severity Code Description Project File Line Suppression State
Error NETSDK1005 Assets file 'c:\temp\App1\App1\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. App1 C:\Program Files\dotnet\sdk\5.0.100-preview.5.20279.10\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 234

If you read the GitHub issue, you’ll note that it very clearly says “you need to use VS16.7.2”.

Make sure you are using Visual Studio 16.7, not Visual Studio 16.8 preview 2. The point of this post is that if you have both installed side by side, the installation of preview 2 will break your ability to run WinUI for Desktop projects. Adding the global.json file to your solution folder will fix this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *