Search code examples
c#visual-studiouwpmsbuildcsproj

How to set up a UWP class library with the new csproj format with MSBuild.Extras?


I'm trying to create a class library that uses UWP controls (the lower the version the better), and I want it to use the new csproj format.

I figured MSBuild.Sdk.Extras is what I'm after. After reading the Readme I did the following:

  1. I created a .NET Standard class library project and replaced its content with the following:
<Project Sdk="MSBuild.Sdk.Extras">
  <PropertyGroup>
    <TargetFrameworks>uap</TargetFrameworks>
  </PropertyGroup>
</Project>
  1. I added a global.json file with the following content:
{
  "msbuild-sdks": {
    "MSBuild.Sdk.Extras": "2.0.54"
  }
}

But when I try to build the project, I get the following error:

D:\Users\Shimmy\Source\Repos....csproj : error : The expression "[System.Version]::Parse('')" cannot be evaluated. Version string portion was too short or too long. >C:\Users\Shimmy.nuget\packages\msbuild.sdk.extras\2.0.54\Build\Platforms\Windows.targets

I'm willing to hear about other ways of UWP creating class libraries as long as it uses the new format.


Solution

  • This worked:

    <Project Sdk="MSBuild.Sdk.Extras">
      <PropertyGroup>
        <TargetFramework>uap10.0</TargetFramework>
      </PropertyGroup>
    </Project>
    

    Or one of the specific versions, i.e. uap10.0.16299.