How to emulate /p msbuild parameter in Visual Studio build?
Asked Answered
W

2

4

That the logical follow-up for the my previous question: "How to check all projects in solution for some criteria?"
I was given quite a good answer to use CustomAfterMicrosoftCommonTargets, CustomBeforeMicrosoftCommonTargets. They do work, so I decided not to stop in the middle.

Issue is that I don't want machine-wide tasks. It's not a good idea neither for me (it will affect other builds. sure, this can be handled, but still), nor for my teammates (I don't want to let them put something in system folders... ), nor for build server. What is needed: solution to be built from scratch out of source control on clean machine with either Visual Studio or MSBuild.

It appeared that Custom*MicrosoftCommonTargets are regular properties.

So, how to specify this property? It works pretty fine when to set it from command line. That's strange, but it appears that bit of magic present here: property passed as command line parameter to one build is transitively passed to all nested builds!

That's fine for build server. But this won't work with Visual Studio build. And even declaring solution-level property won't help: neither static, nor dynamic properties are transfer to nested builds.

...I have a hacky idea to set environment variable on before solution build and erase it on after. But I don't like it. Any better ideas?

Wigfall answered 20/4, 2011 at 17:48 Comment(0)
P
0

I use a bit different technique then @Spider M9. I want that all projects in solution tree/all subdirectories from current directory use extended build throw Custom*MicrosoftCommonTargets. I don't like to be forced to change every new project to import custom targets/props.

I place special file, let's say msbuild.include, in the root directory and my custom targets loader for every project tries to find it in ., ..\, ..\..\, and so on. msbuild.include contains flags that triggers execution of custom actions. If loader can't find this file it disables loading all custom targets and stoppes. This gives me ability to use my build extensions with projects from work repositories and to not use with opensource projects.

If you are interested in I can publish loader. It's a pretty simple and elegant solution.

For example I can sign any assembly in all projects in all subfolders with my key.

Possess answered 21/4, 2011 at 6:5 Comment(4)
Yes, please. It looks exactly like what I need.Wigfall
OK. I'm not sure that I can do it today.Possess
I'm not in a hurry, so that's okay.Wigfall
Sergio, Can you please elaborate your solution and on the "custom targets loader". I have the same problem that I don't want to modify every project file and more over modifications to the project file are gone when you make any change to the Project from Visual Studio.Sanskrit
I
0

I always set up every project to import a standard .props file. Use the GetDirectoryNameOfFileAbove property function (see MSDN) to find it. Do this as the first line of every project file. Once established, you can redirect from that file to other imports. Another trick is to have that standard import (that would obviously be under version control) import conditionally another .props file only if it exists. This optional file would not be in version control, but is available for any developer to create and modify with their own private/temporary properties or other behavior.

Intort answered 21/4, 2011 at 1:8 Comment(1)
This solution still requred manual modification of every .csproj file - exactly the thing I'm trying to aviod.Wigfall
P
0

I use a bit different technique then @Spider M9. I want that all projects in solution tree/all subdirectories from current directory use extended build throw Custom*MicrosoftCommonTargets. I don't like to be forced to change every new project to import custom targets/props.

I place special file, let's say msbuild.include, in the root directory and my custom targets loader for every project tries to find it in ., ..\, ..\..\, and so on. msbuild.include contains flags that triggers execution of custom actions. If loader can't find this file it disables loading all custom targets and stoppes. This gives me ability to use my build extensions with projects from work repositories and to not use with opensource projects.

If you are interested in I can publish loader. It's a pretty simple and elegant solution.

For example I can sign any assembly in all projects in all subfolders with my key.

Possess answered 21/4, 2011 at 6:5 Comment(4)
Yes, please. It looks exactly like what I need.Wigfall
OK. I'm not sure that I can do it today.Possess
I'm not in a hurry, so that's okay.Wigfall
Sergio, Can you please elaborate your solution and on the "custom targets loader". I have the same problem that I don't want to modify every project file and more over modifications to the project file are gone when you make any change to the Project from Visual Studio.Sanskrit

© 2022 - 2024 — McMap. All rights reserved.