我有一个要对我的项目文件运行的操作,以规范它们中XML标记的顺序(以便更轻松地查看版本控制中发生了什么变化,而不会出现由Visual Studio重新排列所有这些误报而导致的错误肯定。标签),但仅适用于旧格式文件-它将破坏新格式的项目文件。确定项目文件是使用旧格式还是新格式的最佳方法是什么?我当时想我可以在根Sdk
标记上搜索Project
属性,并将其作为新格式的标志,但是我不知道所有新格式的项目文件是否都具有该属性。还是可以保证旧格式的项目文件不会...
答案 0 :(得分:0)
我可以想到两种方式:
<Project Sdk="..." />
是一种方法。<Import ... Sdk="..." />
<Project>
<user prop here>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk/1.0.0.0" />
...
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk/1.0.0.0" />
<user target here>
</Project>
<!-- this is now part of the SDK, so only a non-SDK project would import it without a warning. However, this wasn't in projects by default until VS2017 I think -->
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<!-- This is also brought in by the SDK now, and might be a more reliable indicator -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<!-- this property is deprecated -->
<ProjectGuid>...</ProjectGuid>
<!-- in SDK-style, this is replaced by <TargetFramework> -->
<TargetFrameworkVersion>...</TargetFrameworkVersion>
</PropertyGroup>