我正在将我的项目迁移到新的visual studio 2017格式,这种格式现在只适用于所有标准库,我遇到了使用Wpf/Xaml的UI库的问题.
我无法弄清楚如何为我的用户控件执行此操作.旧项目似乎不再有效.
任何人都知道如何做到这一点,或者甚至可能.
我在Visual Studio 2017中使用新的CSPROJ格式创建了一个WPF应用程序.
通过
我可以成功构建并运行该应用程序.但是,我有一个问题,即代码编辑器无法识别XAML中的任何控件,因此我在编辑器中得到错误的错误而没有智能感知.
项目文件:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
<TargetFramework>net45</TargetFramework>
<ProjectGuid>{030D04DA-D603-4D4C-95F7-B6F725A6829E}</ProjectGuid>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"> …Run Code Online (Sandbox Code Playgroud) c# wpf visual-studio-2017 roslyn-project-system common-project-system
是否有人成功.csproj为使用新的SDK样式.csproj格式的UWP项目创建了文件?我从有关WPF的问题中汲取了灵感,这使我90%地了解了WPF。
之后,我开始使用MSBuild.Sdk.Extras程序包,该程序包使我可以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"> …Run Code Online (Sandbox Code Playgroud)