如何转移项目 Wpf 以新格式 VS2017

我将我的项目转移到新格式 visual studio 2017, 适用于所有标准库,只有现在我遇到了我的图书馆的问题 UI, 我在哪里使用 Wpf / Xaml.

我无法理解如何为我的用户控件执行此操作。 旧点似乎不再有效。

有没有人知道如何做到这一点,也是可能的。
已邀请:

帅驴

赞同来自:

13 十二月 2018 -
https://blogs.msdn.microsoft.c ... orks/
.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

不会发生。

没有错误
Unable to run your project. The "RunCommand" property is not defined.

不会发生。

包括已配置的默认参数和资源。

模板:


<project sdk="Microsoft.NET.Sdk" toolsversion="15.0">
<propertygroup>
<languagetargets>$/MSBuildExtensionsPath/\$/VisualStudioVersion/\Bin\Microsoft.CSharp.targets</languagetargets>
<targetframework>net47</targetframework>
<outputtype>WinExe</outputtype>
<startupobject></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 exclude="App.xaml" include="**\*.xaml">
<subtype>Designer</subtype>
<generator>MSBuild:UpdateDesignTimeXaml</generator>
</page>
<compile dependentupon="%/Filename/" subtype="Code" update="**\*.xaml.cs"></compile>
<!-- Resources -->
<embeddedresource generator="ResXFileCodeGenerator" lastgenoutput="Resources.Designer.cs" update="Properties\Resources.resx"></embeddedresource>
<compile autogen="True" dependentupon="Resources.resx" designtime="True" update="Properties\Resources.Designer.cs"></compile>
<!-- Settings -->
<none generator="SettingsSingleFileGenerator" lastgenoutput="Settings.Designer.cs" update="Properties\Settings.settings"></none>
<compile autogen="True" dependentupon="Settings.settings" update="Properties\Settings.Designer.cs"></compile>
</itemgroup>
<itemgroup>
<reference include="PresentationCore"></reference>
<reference include="PresentationFramework"></reference>
<reference include="System.Xaml"></reference>
<reference include="WindowsBase"></reference>
</itemgroup>
</project>

冰洋

赞同来自:

在一些搜索和样本和错误之后,我得到了他的工作!

这是最终的 wpf csproj:


<project sdk="Microsoft.NET.Sdk">
<propertygroup>
<languagetargets>$/MSBuildExtensionsPath/\$/VisualStudioVersion/\Bin\Microsoft.CSharp.targets</languagetargets>
<targetframeworks>net451</targetframeworks>
<rootnamespace>MyWpfLibrary</rootnamespace>
<assemblyname>MyWpfLibrary</assemblyname>
</propertygroup>
<itemgroup>
<packagereference include="Rx-Xaml" version="2.2.5"></packagereference>
<packagereference include="reactiveui-core" version="7.2.0"></packagereference>
</itemgroup>
<itemgroup>
<projectreference include="MyOtherLibrary.csproj"></projectreference>
</itemgroup>
<itemgroup>
<reference include="PresentationCore"></reference>
<reference include="PresentationFramework"></reference>
<reference include="ReachFramework"></reference>
<reference include="System.Net"></reference>
<reference include="System.Printing"></reference>
<reference include="System.Xaml"></reference>
</itemgroup>
<itemgroup>
<embeddedresource generator="ResXFileCodeGenerator" lastgenoutput="Resources.Designer.cs" update="Properties\Resources.resx"></embeddedresource>
<compile autogen="True" dependentupon="Resources.resx" designtime="True" update="Properties\Resources.Designer.cs"></compile>
<page generator="MSBuild:Compile" include="**\*.xaml" subtype="Designer"></page>
<compile dependentupon="%/Filename/" subtype="Designer" update="**\*.xaml.cs"></compile>
<resource include="Fonts\*.otf"></resource>
<resource include="Images\*.png"></resource>
</itemgroup>
<import condition="Exists/'$/MSBuildSDKExtrasTargets/'/" project="$/MSBuildSDKExtrasTargets/"></import>
</project>

窦买办

赞同来自:

以上解决方案适用于 Wpf DLL,但我回来了,因为 Resharper 和设计师 Visual Studio 这种变化后不再运作。 基本上是因为他们无法连接 xaml 和在开发期间的代码。 但该项目是编制和工作的。

对于可执行文件 wpf 您需要执行以下操作:


<project sdk="Microsoft.NET.Sdk">
<propertygroup>
<languagetargets>$/MSBuildExtensionsPath/\$/VisualStudioVersion/\Bin\Microsoft.CSharp.targets</languagetargets>
<targetframework>net451</targetframework>
<outputtype>WinExe</outputtype>
<rootnamespace>MyNamespace</rootnamespace>
<assemblyname>MyExe</assemblyname>
<applicationicon>MyExe.ico</applicationicon>
<applicationmanifest>app.manifest</applicationmanifest>
<startupobject>MyNamespace.App</startupobject>
</propertygroup>
<itemgroup>
<reference include="PresentationCore"></reference>
<reference include="PresentationFramework"></reference>
<reference include="System.Xaml"></reference>
<reference include="WindowsBase"></reference>
</itemgroup>
<itemgroup>
<embeddedresource generator="ResXFileCodeGenerator" lastgenoutput="Resources.Designer.cs" update="Properties\Resources.resx"></embeddedresource>
<compile autogen="True" dependentupon="Resources.resx" designtime="True" update="Properties\Resources.Designer.cs"></compile>
<none generator="SettingsSingleFileGenerator" lastgenoutput="Settings.Designer.cs" update="Properties\Settings.settings"></none>
<compile autogen="True" dependentupon="Settings.settings" designtime="True" update="Properties\Settings.Designer.cs"></compile>
<page generator="MSBuild:Compile" include="MainWindow.xaml" subtype="Designer"></page>
<compile dependentupon="MainWindow.xaml" update="MainWindow.xaml.cs"></compile>
<resource include="Images\*.png"></resource>
<applicationdefinition generator="XamlIntelliSenseFileGenerator" include="App.xaml" subtype="Designer"></applicationdefinition>
<compile dependentupon="App.xaml" update="App.xaml.cs"></compile>
</itemgroup>
<import condition="Exists/'$/MSBuildSDKExtrasTargets/'/" project="$/MSBuildSDKExtrasTargets/"></import>
</project>

喜特乐

赞同来自:


https://github.com/SunburstApp ... k.WPF
, 是什么允许你用它 .NET SDK. 这是应用程序的完整示例 WPF, 任何文件都在哪里
.cs


.xaml

将被包括在内

自动地

:


<project sdk="Sunburst.NET.Sdk.WPF/1.0.47">
<propertygroup>
<outputtype>WinExe</outputtype>
<targetframework>net40</targetframework>
</propertygroup>
<itemgroup>
<projectreference include="../WpfMath/WpfMath.csproj"></projectreference>
</itemgroup>
</project>


当您创建此项目时
msbuild

/我特别不是幸运的
dotnet build

/, 它会自动加载 SDK 的 NuGet 并设置一切。

郭文康

赞同来自:

现在,当 .NET Core 3 被释放,如果可以,你必须使用它。

但如果没有,我发现我只能为元素创建一个单独的常见项目 XAML, 我可以从项目中引用这个项目 SDK. 一切都是正确的。

请注意,设计师 XAML 不起作用 - 不 Intellisense, 既不是红色的咒骂。 Visual Studio 打开文件 XAML 使用编辑器 XML.

郭文康

赞同来自:

以上决定可能无法使用 Xamarin.Platforms.WPF 在 VS2019

这是项目/以前的回复/, 专为框架而设计 .net /而不是主要申请 .net/, 但能够处理标准依赖项 .net:


<project sdk="Microsoft.NET.Sdk">
<propertygroup>
<outputtype>WinExe</outputtype>
<rootnamespace>TestWPF</rootnamespace>
<assemblyname>TestWPF</assemblyname>
<targetframework>net461</targetframework>
<autogeneratebindingredirects>true</autogeneratebindingredirects>
<deterministic>true</deterministic>
</propertygroup>
<propertygroup condition=" '$/Configuration/' == 'Debug' ">
<debugtype>full</debugtype>
</propertygroup>
<propertygroup condition=" '$/Configuration/' == 'Release' ">
<debugtype>pdbonly</debugtype>
</propertygroup>
<itemgroup>
<packagereference include="Microsoft.NETCore.Platforms" version="3.0.0"></packagereference>
<packagereference include="Xamarin.Forms" version="4.2.0.848062"></packagereference>
<packagereference include="Xamarin.Forms.Platform.WPF" version="4.2.0.848062"></packagereference>
</itemgroup>
<itemgroup>
<reference include="PresentationCore"></reference>
<reference include="PresentationFramework"></reference>
<reference include="WindowsBase"></reference>
<reference include="System.Xaml"></reference>
</itemgroup>
<itemgroup>
<embeddedresource generator="ResXFileCodeGenerator" lastgenoutput="Resources.Designer.cs" update="Properties\Resources.resx"></embeddedresource>
<compile autogen="True" dependentupon="Resources.resx" designtime="True" update="Properties\Resources.Designer.cs"></compile>
<none generator="SettingsSingleFileGenerator" lastgenoutput="Settings.Designer.cs" update="Properties\Settings.settings"></none>
<compile autogen="True" dependentupon="Settings.settings" designtime="True" update="Properties\Settings.Designer.cs"></compile>
<applicationdefinition generator="MSBuild:Compile" include="App.xaml"></applicationdefinition>
<page exclude="App.xaml" generator="MSBuild:Compile" include="**\*.xaml" subtype="Designer"></page>
<compile dependentupon="%/Filename/" subtype="Designer" update="**\*.xaml.cs"></compile>
<embeddedresource remove="**\*.xaml"></embeddedresource>
</itemgroup>
<import condition="Exists/'$/MSBuildSDKExtrasTargets/'/" project="$/MSBuildSDKExtrasTargets/"></import>
</project>

要回复问题请先登录注册