在Visual Studio中构建事件自定义

时间:2008-11-19 12:34:02

标签: visual-studio macros customization post-build

有没有办法自定义post build事件宏,我想将新程序集移动到由程序集版本命名的同一目录中的子文件夹,即

复制$(TargetDir)$(TargetFileName)$(TargetDir)$( ASSEMBLYVERSION )\ $(TargetFileName)

然而,没有这样的“宏观”。 构建可执行文件以获得类似的版本

call foo.bat $(TargetName)

我们让foo.bat通过调用托管应用程序评估目标版本,该应用程序打印您传入的程序集的版本,比如说GetVersion.exe

for /f %%t in ('GetVersion.exe %1') do (
        set _version=%%t
    )
echo %_version%

任何想法?当然有一种方法可以直接自定义宏?

1 个答案:

答案 0 :(得分:1)

不确定是否可以通过构建后的脚本完成,但您可以修改项目文件以执行相同的操作。

右键单击项目并选择“卸载项目”。

然后再次右键单击它并选择“编辑项目”。

现在在项目文件中,找到“AfterBuild”目标。它通常位于文件的底部并注释掉。

取消注释,或者只是粘贴以下内容:

<Target Name="AfterBuild">
  <GetAssemblyIdentity AssemblyFiles="path\to\bin\$(Configuration)\$(OutputName).dll">
    <Output TaskParameter="Assemblies" ItemName="AssemblyVersion"/>
  </GetAssemblyIdentity>

  <Copy 
    SourceFiles="path\to\bin\$(Configuration)\$(OutputName).dll" 
    DestinationFiles="path\to\bin\$(Configuration)\%(AssemblyVersion.Version)\$(OutputName).dll" />
</Target>

最后再次右键单击该项目,然后选择“重新加载项目”。

您可能需要摆弄变量名称,并可能在复制之前创建该文件夹。希望这会有所帮助。

来自Automated installer version numbers for WiX

的想法