Bug 31212 - Macros supported on Visual Studio Projects not expanding by xbuild
Summary: Macros supported on Visual Studio Projects not expanding by xbuild
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Ms.Build (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-17 22:52 UTC by Avenger
Modified: 2016-04-12 21:36 UTC (History)
3 users (show)

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


Attachments

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:
$(ProjectPath)
$(ProjectFileName)

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:
https://msdn.microsoft.com/en-us/library/42x5kfw4.aspx

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:

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

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.

Note You need to log in before you can comment on or make changes to this bug.