简体   繁体   English

如何在Visual Studio的post-build事件中获取解决方案目录的动态路径

[英]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.我的解决方案中有七个代码库项目,我有 3 个不同类型的网站,它们使用来自 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.现在我想将后期构建脚本放在我的参考代码库项目之一中,以便在构建完成后将一个特定的 DLL 放入我的网站 bin 目录。

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.例如,我有一个名为“references”的参考项目,并且在其项目属性中将放置以下代码以获取解决方案网站 bin 目录。

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".以上内容适用于我的一个名为“Com.Emirates.Pss.Ibe.UI”的网站项目,问题出在一位用户签入“引用”项目,然后其他开发人员获取最新的引用项目时“ Com.Emirates.Pss.Ibe.UI”在其构建后脚本中,但其解决方案网站目录是“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.我怎样才能使 xcopy /Y $(ProjectDir)Tridion $(SolutionDir) Com.Emirates.Pss.Ibe.UI \\Bin(粗体部分是动态的,这样谁签入用户就可以轻松地构建那里的应用程序,而无需进行更改.

Here is a list of all the different Post-Build event macros .这是所有不同的Post-Build 事件宏的列表

I'm guessing you want to use the $(ProjectDir) macro, if I understood correctly?我猜你想使用$(ProjectDir)宏,如果我理解正确的话?

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:另一种选择,如果您使用 MSBuild,您可以在 VS 中添加用户定义的宏变量,创建您自己的属性表,如示例所示:

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

Usage: xcopy /Y $(ProjectDir)Tridion $(SolutionDir)$(MyProj)\\Bin用法: 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.最后一个选项是在 MAIN 项目(将在之前运行)中设置一个具有特定项目名称的环境变量,并从references项目中引用它。

eg例如

In project #1 set a Pre -Build event with: SETX MyProj Com.Emirates.Pss.Ibe.UI在项目 #1 中设置一个Pre- Build 事件: SETX MyProj Com.Emirates.Pss.Ibe.UI

In Reference project, copy it using xcopy /Y $(ProjectDir)Tridion $(SolutionDir)%MyProj%\\Bin在参考项目中,使用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.应该注意的是 SETX 和 SET 之间的区别在于,即使在 CMD 窗口(运行 MSBuild)关闭之后,SETX 也会保留变量。 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.但是,您可能必须在第一次运行时关闭并重新打开 Visual Studio,因为使用 SETX 创建的变量只会在使用此命令后创建的任何 CMD 窗口上开始工作。

I simply pass $(SolutionDir) as an argument to the .cmd file you are invoking in your PostBuild event command line.我只是将 $(SolutionDir) 作为参数传递给您在 PostBuild 事件命令行中调用的 .cmd 文件。 Similarily if you want $(ProjectName) or any other of the VS macros accessible in the PostBuild cmd.同样,如果您想要 $(ProjectName) 或任何其他可在 PostBuild cmd 中访问的 VS 宏。

I resolved my issue by putting below code in "references" project PostBuildEvent:我通过将以下代码放在“参考”项目 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生成后事件错误Visual Studio 2008 - Post-build Event error visual studio 2008 Visual Studio Post-build事件:用于(set)命令中的%f - Visual Studio Post-build event: for %f in (set) command 如何在构建后事件中获取版本号 - How to get version number in post-build event Visual Studio生成后事件和批处理命令 - Visual Studio Post-Build Events and Batch Commands Visual Studio发布发布/或生成解决方案ZIP - Visual Studio post publish/or build solution ZIP 在 Visual Studio 构建后事件中获取 .NET 目标平台 - Get .NET target platform in visual studio post build event Dotfuscator生成后事件以代码1退出 - Dotfuscator Post-Build Event Exited With Code 1 在MonoDevelop和Visual Studio上使用post-build脚本制作项目的最佳方法是什么? - Best way to make a project with post-build script work on MonoDevelop and Visual Studio? 通过 NuGet 提供命令行工具以在 Visual Studio 中的生成后事件中使用 - Deliver command-line tool via NuGet for use in post-build events in Visual Studio 对于我在 Visual Studio 2013 中的类库项目; 使用后期构建事件如何将创建的 dll 复制到另一个路径? - For my class Library project in visual Studio 2013 ; Using post build event how do I copy the created dll to another path?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM