在我们的 .net 项目中更改 MSBuild 工具集 (ToolsVersion) 有什么缺点?

what are the drawbacks of changing the MSBuild Toolset (ToolsVersion) in our .net projects?

我知道 MSBuild 工具集(ToolsVersion) 的工作原理和工作方式,但不明白如果 changing/using 较低或较高的 ToolVersion 来自项目文件或 CLI。

Need to know the pro and cons Please...

what are the drawbacks of changing the MSBuild Toolset (ToolsVersion) in our .net projects?

据我所知,ToolsVersion指定了特定版本的构建机制,实际上,这意味着使用不同版本的 MSBuild 构建项目。参见 this link

:

VS2019(MSBuild 16.0):ToolsVersion=Current,VS2017(MSBuild 15.0):ToolsVersion=15.0,VS2015(MSBuild 14.0):ToolsVersion=14.0,VS2013:ToolsVersion=12.0

但是,每个新版本的 MSBuild 都会有一些新功能和一些您可以在 proj 文件中使用的特殊任务。正因如此,MSBuild支持向下兼容,高版本的MSBuild支持编译低版本VS创建的项目,以及之前低版本的新特性。

举个例子,如果你在VS2015中创建一个新项目,你可以使用ToolsVersion 14.015.0Current而不用任何错误。

如果您使用较低的 ToolsVersion 来构建您的项目,它会出现一些错误,例如 Could not find the assembly reference xxxxxxx 或缺少 DLL 方法。

因此,我们建议您使用高于当前项目版本的ToolsVersion(MSBuild),而不是低于当前项目版本的MSBuild您当前的项目。而如果你当前的项目没有任何特殊版本的方法或特性,使用低版本也没有问题,但一般不推荐这样做。并使用最新版本的MSBuild来构建你的项目,它可能会有性能优化和改进。

希望对您有所帮助。