2

Why can't I use MSBuild macros in a C# Project's properties? These all work find in a CPP project.

For example:

  • Create an empty C# console application
  • Change the main method to take command line arguments
  • Right click on the project in solution explorer and click properties
  • Choose "Debug" on the left side
  • In Command Line Argument's, enter: "$(SolutionDir)"
  • Debug your program
  • Notice that the argument is quite literally $(SolutionDir) rather than what it translates to.

I have the same problem with "Xml documentation file path" and other fields.

6
  • 1
    I expect the UI is just quoting the values in dialog boxes. What happens if you edit the project file directly instead? Commented Jun 6, 2018 at 21:00
  • Interestingly, I cannot even find the debug startup arguments in the csproj file. Perhaps they are saved somewhere else? Commented Jun 6, 2018 at 21:02
  • 1
    I suspect they're in the csproj.user file. Commented Jun 6, 2018 at 21:03
  • You were correct. Thanks! Commented Jun 6, 2018 at 21:27
  • @Christopher Pisz, Any update for this issue? Have you resolved this issue? If not, would you please let me know the latest information about this issue? Commented Jun 11, 2018 at 3:04

1 Answer 1

1

Why can't I use MSBuild macros in a C# Project's properties? These all work find in a CPP project.

This is because the way C# and CPP project introduce macros is not the same.

For C# project, it introduced by the .props, .targets files, for example, the Microsoft.CSharp.targets file. In your project file .csproj you will find following Import:

<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.

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). Therefore, a project configuration defined in a .vcproj file can inherit project settings from one or more property sheets (.vsprops files). 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.

You can check following document for some more details:

Common macros for build commands and properties

Property Sheets (C++)

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I do not follow. I understand property sheets and target files and how prop sheets are not available in C# projects. However, I don't know what that all has to do with the UI translating MSBuild macros in projects for cpp, but not for c#. I think you might have explained it, but I am not following it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.