microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.38k stars 2.22k forks source link

Is it possible to use an SDK-style .csproj for a UWP project? #854

Closed pingzing closed 6 years ago

pingzing commented 6 years ago

(For additional context, I also posted this question on StackOverflow.)

So after some success in migrating a small WPF project to use the new SDK-style .csproj, I decided to try to see if it was possible to do so for UWP. Unfortunately, I seem to have hit a dead end, and decided to appeal to those who might know more.

Is this possible, even theoretically? Can you offer any guidance on the two issues I'm experiencing?

1) Dependency .dlls aren't copied to /bin. 2) Visual Studio complains that built-in XAML types "aren't valid in a Universal Windows Project".

For the sake of completeness, my .csproj looks like this:

<Project Sdk="MSBuild.Sdk.Extras">
  <PropertyGroup>    
    <!--UWP specific stuff-->        
    <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.17134.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
    <TargetFrameworks>uap10.0</TargetFrameworks>
    <OutputType>AppContainerExe</OutputType>    
    <LanguageTargets>$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets</LanguageTargets>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <PackageCertificateKeyFile>FabulousTest.UWP_TemporaryKey.pfx</PackageCertificateKeyFile>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)'=='Release'">
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <PlatformTarget>x86</PlatformTarget>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
  </PropertyGroup>  

  <ItemGroup>    

    <!--XAML stuff-->
    <ApplicationDefinition Include="App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </ApplicationDefinition>

    <Page Include="**\*.xaml" Exclude="App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>        
    <Compile Update="**\*.xaml.cs" SubType="Code" DependentUpon="%(Filename)" />

     <AppxManifest Include="Package.appxmanifest">
      <SubType>Designer</SubType>
    </AppxManifest>

    <!--Local projects-->

    <!--Nuget references-->
  </ItemGroup>      

</Project>

Would appreciate any information! Thanks!

jnm2 commented 6 years ago

Have you seen https://github.com/onovotny/MSBuildSdkExtras#getting-started-vs-156?

pingzing commented 6 years ago

Yep! It's what I'm using at the moment. As far as I can tell, the SDK-style .csproj won't accept uap10.0 as a TargetFramework without it.

jnm2 commented 6 years ago

Missed that, sorry! 😄 @onovotny is the author and is probably the best person to answer this question.

clairernovotny commented 6 years ago

You cannot currently use the SDK style projects for an application itself, only for UWP class libraries. The project system needs to support deploying and launching it in the correct way as well.

pingzing commented 6 years ago

Got it! Sort of what I expected. (Honestly kind of surprised I even got it to compile).

Thanks. I think we can close this issue now.

hansmbakker commented 5 years ago

I got this answer on Twitter. Not an official statement of course, but still a pity.

@onovotny did you mean that, even with additions to MSBuildSdkExtras, we would depend on the MSBuild team to make SDK-style UWP projects possible?

clairernovotny commented 5 years ago

It's possible to use the Extras for class libraries, but in order to use it for applications, it requires additional work from the project system as that handles deployment and starting the debugger.

hansmbakker commented 5 years ago

Yes, I meant for applications. Thank you for the clarification.

MelbourneDeveloper commented 4 years ago

@clairernovotny , it doesn't seem to be true that you can create UWP class libraries with SDK style projects. This Github issue seems to say that it's not possible: https://github.com/dotnet/sdk/issues/1408

Even this document says that uap and uap10.0 are supposed to be valid frameworks, but they just aren't. This is the error I get when I try to target either one in a SDK style project:

Severity Code Description Project File Line Suppression State Error NETSDK1013 The TargetFramework value 'uap' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly. Device.Net C:\Program Files\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets 93

clairernovotny commented 4 years ago

You can do it if you use the MSBuild.Sdk.Extras package: https://github.com/novotnyllc/MSBuildSdkExtras

You'll also need to use msbuild.exe to build as dotnet build doesn't have the correct targets.

MelbourneDeveloper commented 4 years ago

@clairernovotny ok thanks. I'll try.

Juansero29 commented 3 years ago

Is creating an UWP app project using the SDK.Extra style .csproj still impossible as of now?

MelbourneDeveloper commented 3 years ago

I've used it but I ended up having to switch back to separate csproj files because of all the issues