c# - 如何将 Wpf 项目迁移到新的 VS2017 格式

标签 c# wpf visual-studio-2017

我正在将我的项目迁移到新的 visual studio 2017 格式,它适用于所有标准库,但现在我在使用 Wpf/Xaml 的 UI 库中遇到问题。

我不知道如何为我的用户控件执行此操作。旧项目似乎不再有效。

任何人都知道如何做到这一点,或者是否可能。

最佳答案

2018 年 12 月 13 日 - .NET Core 3 Preview 1 was announced

.NET Core 3 将支持 WPF 和 WinForms 应用程序。您可以使用预览版 SDK 进行尝试:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
</Project>

上一个答案

您可以使用下面的模板替换旧的 .csproj。它解决了其他人模板的几个问题。

  1. 您不必像某些建议那样包含中间 *.g.cs 文件。
  2. 不会发生Main not found错误。
  3. 无法运行您的项目。 “RunCommand”属性未定义。 将发生错误。
  4. 包括已配置的默认设置和资源。

模板:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <TargetFramework>net47</TargetFramework>
    <OutputType>WinExe</OutputType>
    <StartupObject />
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <!-- App.xaml -->
    <ApplicationDefinition Include="App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </ApplicationDefinition>

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

    <!-- Resources -->
    <EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
    <Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />

    <!-- Settings -->
    <None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
    <Compile Update="Properties\Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" />

  </ItemGroup>

  <ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>
</Project>

关于c# - 如何将 Wpf 项目迁移到新的 VS2017 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43693591/

相关文章:

c++ - 为什么这个enable_if函数模板不能专用于VS2017?

c# - 在 WCF 中缓存?

c# - WCF 4 关闭客户端代理

c# - WPF 工具栏控制溢出量

c# - 如何保存和使用应用程序的窗口大小?

wpf - DevExpress GridControl 列自动宽度

visual-studio-2017 - 在哪里可以下载 Visual Studio 2017 的远程调试器

c# - 什么是数据表或自定义对象,效率更高?

c# - 在 C# 8.0 中反序列化对象时处理临时空引用类型?

asp.net - XSD 文件无法在 Visual Studio 2017 的表设计模式下打开