【问题标题】:Post Build Events Customization In Visual Studio在 Visual Studio 中自定义生成后事件
【发布时间】:2008-11-19 12:34:01
【问题描述】:

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

复制 $(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%

有什么想法吗??肯定有办法直接自定义宏??

【问题讨论】:

    标签: visual-studio macros customization post-build


    【解决方案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>
    

    最后再次右击项目,选择“Reload Project”。

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

    想法来自Automated installer version numbers for WiX

    【讨论】:

    • 谢谢,对我很有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    相关资源
    最近更新 更多