Msbuild get OutputPath from main project
Say I have a game.exe
that depends on engine.dll
. When I build the game.csproj
I want the engine.csproj
to copy some stuff to the OutputPath of the project that is referencing it.
So in this example case, I want engine.csproj
to copy something to the OutputPath of game.csproj
How do I get the $(OutputPath) of game.csproj
in engine.csproj
?
The reason I want to do this is because I'm building a content project in game and engine like this:
<Target Name="BuildContent">
<M开发者_如何学编程SBuild Projects="Content\Content.contentproj"
Properties="OutputPath=MAINPROJECTPATH" />
</Target>
So I need to specify the OutputPath to the 'main project' which is the game.
With a bit nosing around in some of the msbuild targets I found the solution.
I should pass through the Parent properties like this
<Target Name="BuildContent">
<MSBuild Projects="Content\Content.contentproj"
Properties="ParentOutputDir=$(ParentOutputDir);
ParentIntermediateDir=$(ParentIntermediateDir);
ParentProjectDir=$(ProjectDir);" />
</Target>
First off, it is not clear from the question exactly what extra files you need to be copied that will not happen automatically using inter-project references.
If the Game project includes a project reference (rather then just a DLL file reference) to the Engine project, msbuild should copy all the output from Engine into the Game output directory, doesn't it?
If you really do need to manually copy files between projects, then I do not believe there is any easy way to find out which projects reference the current project, so it would probably be simpler to create a level of indirection with Engine pushing files half way and Game (or any other projects that need to include those files) pulling the files the rest of the way:
- Some post-build event code in Engine.csproj created a "References" directory under SolutionDir and copies the files it wants to share into there.
- Then Game.csproj can include the files from the "References" directory - either as direct file references, or by copying with some pre-build event code in Game.csproj
精彩评论