如何将 Wpf 项目迁移到新的 VS2017 格式 [英] How-to migrate Wpf projects to the new VS2017 format

查看:14
本文介绍了如何将 Wpf 项目迁移到新的 VS2017 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的项目迁移到新的 Visual Studio 2017 格式,该格式仅适用于所有标准库,现在我在使用 Wpf/Xaml 的 UI 库中遇到问题.

I'm migrating my projects to the new visual studio 2017 format which is working nicely for all standard libraries only now I run into problems with my UI libraries where I use Wpf / Xaml.

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

I cannot figure out howto do this for my user controls. The old item doesn't seem to be valid anymore.

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

Anybody has an idea howto do this or if it's even possible.

推荐答案

2018 年 12 月 13 日 - .NET Core 3 Preview 1 发布

.NET Core 3 将支持 WPF 和 WinForms 应用程序.你可以试试 SDK 的预览版:

.NET Core 3 will support WPF and WinForms applications. You may try it with Preview version of SDK:

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

上一个答案

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

You can use template below to replace old .csproj with. It resolves couple of issues other people templates had.

  1. 您不必像一些建议的那样包含中间 *.g.cs 文件.
  2. 不会出现Main not found错误.
  3. 无法运行您的项目.RunCommand"属性未定义.会发生错误.
  4. 包括已配置的默认设置和资源.
  1. You don't have to include intermediary *.g.cs files like some suggested to do.
  2. No Main not found error will occur.
  3. No Unable to run your project. The "RunCommand" property is not defined. error will occur.
  4. Includes already configured default Settings and Resources.

模板:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)$(VisualStudioVersion)BinMicrosoft.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="PropertiesResources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
    <Compile Update="PropertiesResources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />

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

  </ItemGroup>

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

这篇关于如何将 Wpf 项目迁移到新的 VS2017 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆