使用post build事件在visual studio中重命名项目输出会产生错误

时间:2012-12-04 13:48:18

标签: c# visual-studio

我想在visual studio 2010中重命名项目exe输出。 发布后 Rename project output before being included into Setup project 我总是收到错误The command rename ... exited with code 1

我的命令是:

rename $(TargetDir)$(TargetFileName) newname.exe

3 个答案:

答案 0 :(得分:8)

  

我想在visual studio 2010中重命名项目exe输出。

我建议您进入项目设置并更改输出程序集名称。与使用后期构建事件相比,这将更简单,更可靠。

你当前的post-build命令有一个无法匹配的双引号可能是问题,但我不会尝试修复它 - 我只是避免它。

答案 1 :(得分:4)

以下是构建后事件的正确命令

rename "$(TargetPath)" "newname.exe"

答案 2 :(得分:1)

我使用Post-Build执行批处理文件和/或PowerShell脚本来执行任何操作:

Post-Build cmd:

if "$(ConfigurationName)" == "Release" start "Version" /D "$(SolutionDir)" /WAIT Version.bat

Version.bat:

@powershell -ExecutionPolicy Unrestricted -File "%~dp0Version.ps1"

IF ERRORLEVEL 1 (
    echo ERROR
    pause
) ELSE (echo OK)

Version.ps1:

# A lot of possibilities here
$scriptDirectory =  [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)