我正在将我的项目迁移到新的 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。它解决了其他人模板的几个问题。
- 您不必像某些建议那样包含中间
*.g.cs
文件。 - 不会发生
Main not found
错误。 - 否
无法运行您的项目。 “RunCommand”属性未定义。
将发生错误。 - 包括已配置的默认设置和资源。
模板:
<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/