ket*_*ket 5 c# msbuild wpf build visual-studio
我有一个使用.NET Core格式定义的.csproj项目。该项目包含由.xaml文件和关联的.cs文件组成的用户控制文件。以前,在这些用户控件上出现编译错误,直到将以下内容添加到.csproj文件中:
<ItemGroup>
<Page Include="**\*.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</Page>
<Compile Update="**\*.xaml.cs" SubType="Code" DependentUpon="%(Filename)" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
那时,解决方案开始在Visual Studio中编译。但是,当我尝试使用dotnet build从命令行进行构建时,构建失败,并出现了我以前在Visual Studio中看到的错误:The name 'InitializeComponent' does not exist in the current context.
有什么想法为什么解决方案可以在VS2017中构建但不使用dotnet构建,或者如何解决这个问题?
编辑:不带PackageReferences的.csproj内容
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LanguageTargets>$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>
<TargetFramework>net45</TargetFramework>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<Page Include="**\*.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</Page>
<Compile Update="**\*.xaml.cs" SubType="Code" DependentUpon="%(Filename)" />
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
对于包含 UserControl 的项目,Dotnet 构建失败(当前上下文中不存在 InitializeComponent)
此时此刻,恐怕您必须使用 MSBuild cli 而不是使用 dotnet build。这是因为 dotnet cli 目前不支持 XAML 文件。MS团队正在努力解决这个问题。
虽然,新的 sdk csproj (net461) 在编译和部署后可以工作,但 Visual Studio 在开发过程中无法.xaml像它期望的 .NET core 视图那样解析文件。
因此,要解决此问题,您可以使用 MSBuild cli 而不是 dotnet build。
有关更多详细信息,请参阅不支持 XAML 文件。
| 归档时间: |
|
| 查看次数: |
638 次 |
| 最近记录: |