简体   繁体   中英

How to get the dynamic path of solution directory in post-build event of Visual Studio

I have seven code library project in my solution and I has 3 different type of websites which are using same code library project from VSS.

Now I want to put post build script in one of my reference code library project so that when build it done it put one specific DLL to my website bin directory.

So example, I have reference project with name "references" and in its project property will put below code to get the solution website bin directory.

xcopy /Y $(ProjectDir)Tridion $(SolutionDir)Com.Emirates.Pss.Ibe.UI\Bin

Above things works fine for my one website project who name is "Com.Emirates.Pss.Ibe.UI", the problem comes as one user checked in the "references" project and then other developer takes the latest of references project it gets "Com.Emirates.Pss.Ibe.UI" in its post build script, however its solution website directory is "Com.Emirates.Pss.MYBooking.UI".

How can I make xcopy /Y $(ProjectDir)Tridion $(SolutionDir) Com.Emirates.Pss.Ibe.UI \\Bin (bold part dynamic, so that who ever does the checked in user can easily build there application without doing the changes.

Here is a list of all the different Post-Build event macros .

I'm guessing you want to use the $(ProjectDir) macro, if I understood correctly?

Another option if you are using MSBuild you can add User Defined Macros variables in VS, create your own property sheet as shown in the example:

<PropertyGroup Label="UserMacros">
      <MyProj>Com.Emirates.Pss.Ibe.UI</MyProj>
</PropertyGroup>

Usage: xcopy /Y $(ProjectDir)Tridion $(SolutionDir)$(MyProj)\\Bin

And one last option , is setting an environment variable with the name of the specific project in MAIN project (which will run before) and reference it from the references project.

eg

In project #1 set a Pre -Build event with: SETX MyProj Com.Emirates.Pss.Ibe.UI

In Reference project, copy it using xcopy /Y $(ProjectDir)Tridion $(SolutionDir)%MyProj%\\Bin

It should be noted the difference between SETX and SET is that SETX keeps the variables even after the CMD window (which runs MSBuild) closes. BUT, you might have to close and reopen Visual Studio the first time you run this as a variable created with SETX only starts working on any CMD window that is created AFTER using this command.

I simply pass $(SolutionDir) as an argument to the .cmd file you are invoking in your PostBuild event command line. Similarily if you want $(ProjectName) or any other of the VS macros accessible in the PostBuild cmd.

I resolved my issue by putting below code in "references" project PostBuildEvent:

if $(SolutionName) == IbeUI-Integrated  xcopy /Y $(ProjectDir)Tridion $(SolutionDir)Com.Emirates.Pss.Ibe.UI\Bin
if $(SolutionName) == MybUI-Integrated  xcopy /Y $(ProjectDir)Tridion $(SolutionDir)Com.Emirates.Pss.Myb.UI\Bin
if $(SolutionName) == OlciUI-Integrated  xcopy /Y $(ProjectDir)Tridion $(SolutionDir)Com.Emirates.Pss.Olci.UI\Bin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM