相关疑难解决方法(0)

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

我正在将我的项目迁移到新的visual studio 2017格式,这种格式现在只适用于所有标准库,我遇到了使用Wpf/Xaml的UI库的问题.

我无法弄清楚如何为我的用户控件执行此操作.旧项目似乎不再有效.

任何人都知道如何做到这一点,或者甚至可能.

c# wpf visual-studio-2017

25
推荐指数
2
解决办法
7657
查看次数

使用新的CSPROJ格式时,WPF控件在代码隐藏中无法识别

我在Visual Studio 2017中使用新的CSPROJ格式创建了一个WPF应用程序.

通过

我可以成功构建并运行该应用程序.但是,我有一个问题,即代码编辑器无法识别XAML中的任何控件,因此我在编辑器中得到错误的错误而没有智能感知.

代码编辑器中的错误错误

重现步骤

  1. 发布VS 2017
  2. 创建一个新的"WPF应用程序(.NET Framework)"C#项目
  3. 编辑csproj文件,如下所示:

项目文件:

<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)
  1. 在MainWindow.xaml中添加一个名为"button1"的按钮,如下所示:

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

8
推荐指数
1
解决办法
1436
查看次数

是否可以为UWP项目使用新的SDK样式的.csproj文件?

是否有人成功.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)

.net c# .net-core uwp

4
推荐指数
1
解决办法
703
查看次数