Bug 31212 - Macros supported on Visual Studio Projects not expanding by xbuild
Summary: Macros supported on Visual Studio Projects not expanding by xbuild
Alias: None
Product: Class Libraries
Classification: Mono
Component: Ms.Build ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-06-17 22:52 UTC by Avenger
Modified: 2018-02-22 23:13 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Avenger 2015-06-17 22:52:56 UTC
Hello, I've noticed some macros we use on Visual Studio are not expanding when trying to build the same project using xbuild.

Some of them are:

Visual studio does not have a lot of project' macros so I guess it is not hard to find what other macros are missing. Also seems these missing macros may be always derived from other ones.

For example, ProjectPath is ProjectDir + ProjectName + ProjectExt
ProjectFileName just ProjectName + ProjectExt.

Not very sure right now, but seems ProjectExt also does not work.

Below a full reference for existing current macros:

If you provide some directions on how to implement these macros, I could give it a try. I had little luck by searching github repo for macro names, to see where they're actually defined.

Apologies if this is a silly/fixed/wontfix/justquestion bug. I really googled around and couldn't find a single match about this lack of macros expansion.
Comment 1 Avenger 2015-06-17 22:57:11 UTC
Sorry, as for test case, just use any of these macros in any <PostBuildEvent /> or <PreBuildEvent />. For example:

 <PostBuildEvent> echo "ProjectPath: $(ProjectPath) / ProjectDir: $(ProjectDir) / ProjectFileName: $(ProjectFileName)"</PostBuildEvent>

in the .csproj file.
Comment 2 Avenger 2015-06-21 11:39:21 UTC
Please note, this happens even if I don't use XamarinStudio. I.e. if I build with

xbuild project.csproj

I looked again and I couldn't find in mono the part where the expandable macros are defined so I could add the missing ones myself.
Comment 3 Marcin Cieślak 2015-06-26 08:34:00 UTC
Did you try plain "msbuild /v:diag" on your project file?

It will show you all pre-defined properties. 

I just tried it both with MSBuild 12.0.31101.0 and xbuild from mono master
and both define some "MSBuildXXX" properties, for example "MSBuildProjectFile".

But those properties you have mentioned are most probably set by VisualStudio, and not internal to msbuild/xbuild.
Comment 4 Marcin Cieślak 2015-06-26 08:43:48 UTC
Having a loser look: not sure if PreBuildEvent/PostBuildEvent etc. hooks are supported at all.
Comment 5 Avenger 2015-06-26 16:43:56 UTC
Hello Marcin,

These properties are indeed set when I type just 'msbuild /v:diag <projectFile>.csproj'

To name some msbuild shows (output from above command):
ProjectDir = A:\devel\Object.NET\Bridge.NET\git\Testing\tests\client\
ProjectExt = .csproj
ProjectFileName = client.csproj
ProjectFlavor = Client
ProjectGuid = {306AD788-87E9-4DF9-A216-95948E024BC8}
ProjectName = client
ProjectPath = A:\devel\Object.NET\Bridge.NET\git\Testing\tests\client\client.csproj

So, isn't it the case these also might be defined in xbuild?

My msbuild reported versions:
Microsoft (R) Build Engine version 12.0.31101.0
[Microsoft .NET Framework, version 4.0.30319.34209]

About pre/post build events being supported or not, they are at least partly supported as I've built projects using them and their tasks have been triggered.

Do you want me to make a sample project in VS2013 that should build with MonoDevelop to illustrate this situation? I can use some "portable" PostBuildEvent like "echo" to illustrate the variables usage.

I believe mono is just missing to define some build macros that current msbuild does. I just couldn't really find in code how I would implement some of those missing macros.

Some of those macros shouldn't be a big deal as they are just derivatives from other macros. But cross-compatibility would be most loved by the community. :}
Comment 6 Avenger 2015-06-26 16:46:33 UTC
Oh additionaly, just to make it clear, pre/post build events are not just triggered but some macros are correctly translated. That's why I am missing just some not all. Some support for macros translating is most definitely in place already. $(OutDir) and $(OS), to name some..
Comment 7 Marcin Cieślak 2015-06-26 16:58:00 UTC
Yeah, I just noticed those events do work in Mono as well; so don't take my word :)

Maybe it is some trivial change, before you work on a fully-fledged example :)
Comment 8 Marcin Cieślak 2016-04-12 21:36:28 UTC
I am not very familiar with the way .NET projects are configured on Windows, but from my limited Visual C++ experience I think you can have a look at the MSBuild macros installed in the MSBuild directory. Those find paths for SDKs and maybe setting your parameters. Various VS components (compilers) install their own stuff there I think.
Comment 9 Marek Safar 2018-02-22 23:13:42 UTC
xbuild has been replaced with msbuild, if you can still reproduce the issue with msbuild please reopen