c# - 是否可以为 UWP 项目使用新的 SDK 样式的 .csproj 文件?

标签 c# .net uwp .net-core

有没有人成功创建一个.csproj使用新 SDK 样式的 UWP 项目的文件 .csproj格式?我的灵感来自 this question关于 WPF,这使我完成了 90% 的工作。

在那之后,我开始使用 MSBuild.Sdk.Extras package , 这让我可以访问 uap10.0作为<TargetFramework> ,经过一些调整后,我实际上用以下 .csproj 编译了它:

<Project Sdk="MSBuild.Sdk.Extras">
  <PropertyGroup>    
    <!--UWP-specific properties-->        
    <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>Test.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>

但是,仍然存在一些问题:

  • 比较库存 UWP 项目和我的自定义项目时,自定义项目的编译 /bin目录似乎不包含依赖项 .dll。 (左侧为自定义项目的/bin 目录,右侧为库存 UWP 项目。)

Image comparing resulting /bin directories

  • Visual Studio 的智能感知提示不支持内置的 XAML 类型。

...这会导致生成的 .exe 在启动时立即崩溃。

有没有人对如何让这个东西到达终点线有建议?

Visual Studio error message

最佳答案

~EDIT MARK II:~它看起来像the current goal是通过 WinUI 3.0 的发布来支持 .NET Core 3(这意味着新的 .csproj 样式),目标是 "some time in 2020"发布。

并且,如果链接失效,第一个是指向 WinUI GitHub 问题的链接,WinUI 项目的 PM 说

Our current plan is that managed WinUI 3 apps uses .NET Core 3 instead of .NET Native at release time.

第二个链接是 WinUI 项目的路线图,上面写着:

We're planning to release WinUI 3.0 in 2020.

2. Preview release: we're planning to release a more complete preview in the first half of 2020

~编辑:~ 在 Build 2019 上有一些安静的公告,即随着 .NET Core 3 的发布,UWP 将开始在 .NET Core 运行时上运行。这似乎可能涉及到新的 .csproj 样式的迁移UWP 项目也是如此。

原帖:

目前看来,答案是否定的。 Per Claire Novotny ,制作 MS Build SDK Extras 的聪明女士:

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.

关于c# - 是否可以为 UWP 项目使用新的 SDK 样式的 .csproj 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52556956/

相关文章:

c# - 使用 .NET 进行 FTP 上传

c# - 共享目标 Universal Apps Windows 10 方法

uwp - 共享uwp应用程序

c# - 无法在新的应用程序域中加载 C 模块

c# - 绑定(bind)到用户控件中的 Observable 集合并从中获取通知

c# - 如何在 IClassifier.GetClassificationSpans 上获取行号?

c# - 如何在 System.Net.WebUtility.UrlEncode 中强制使用 %20 而不是 +

c# - 在 Win 窗体应用程序中禁用右键单击

.net - 使用 foreach/WhenAll 时实际上会发生什么?

c# - 是否可以从 UWP 应用程序格式化/创建分区?