简体   繁体   English

C#Visual Studio项目属性和MSBuild宏

[英]C# Visual Studio Project Properties & MSBuild Macros

Why can't I use MSBuild macros in a C# Project's properties? 为什么我不能在C#项目的属性中使用MSBuild宏? These all work find in a CPP project. 所有这些工作都可以在CPP项目中找到。

For example: 例如:

  • Create an empty C# console application 创建一个空的C#控制台应用程序
  • Change the main method to take command line arguments 更改main方法以采用命令行参数
  • Right click on the project in solution explorer and click properties 右键单击解决方案资源管理器中的项目,然后单击属性
  • Choose "Debug" on the left side 选择左侧的“调试”
  • In Command Line Argument's, enter: "$(SolutionDir)" 在命令行参数中,输入:“ $(SolutionDir)”
  • Debug your program 调试程序
  • Notice that the argument is quite literally $(SolutionDir) rather than what it translates to. 请注意,该参数实际上是$(SolutionDir)而不是其含义。

I have the same problem with "Xml documentation file path" and other fields. 我对“ Xml文档文件路径”和其他字段有相同的问题。

Why can't I use MSBuild macros in a C# Project's properties? 为什么我不能在C#项目的属性中使用MSBuild宏? These all work find in a CPP project. 所有这些工作都可以在CPP项目中找到。

This is because the way C# and CPP project introduce macros is not the same. 这是因为C#和CPP项目引入宏的方式不同。

For C# project, it introduced by the .props , .targets files, for example, the Microsoft.CSharp.targets file. 对于C#项目,它是由.props.targets文件引入的,例如Microsoft.CSharp.targets文件。 In your project file .csproj you will find following Import: 在项目文件.csproj您将找到以下导入:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

For CPP project, it introduced by property sheets, you can get it from View -> Other Windows -> Property Manager , which is not supported by C# project. 对于CPP项目,它是由属性表引入的,您可以从View > Other Windows > Property Manager获得它,而C#项目不支持。

The different: 不同之处:

You can use property sheets to create project configurations that can be applied to multiple projects since project settings that are defined in .vsprops files are inheritable , unlike project settings defined in Project Files (.vcproj files). 您可以使用属性表来创建可应用于多个项目的项目配置,因为.vsprops文件中定义的项目设置是可继承的 ,这与项目文件(.vcproj文件)中定义的项目设置不同。 Therefore, a project configuration defined in a .vcproj file can inherit project settings from one or more property sheets (.vsprops files) . 因此, .vcproj文件中定义的项目配置可以从一个或多个属性表(.vsprops文件)继承项目设置 For more information, see Property Inheritance. 有关更多信息,请参见属性继承。

That the reason why you can use MSBuild macros in a CPP Project's properties but not in C# project. 因此,您可以在CPP项目的属性中使用MSBuild宏,但不能在C#项目中使用MSBuild宏的原因。

You can check following document for some more details: 您可以检查以下文档以了解更多详细信息:

Common macros for build commands and properties 构建命令和属性的通用宏

Property Sheets (C++) 属性表(C ++)

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM