Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio 2012生成后事件-错误代码255_C#_.net_Visual Studio_Post Build Event - Fatal编程技术网

C# Visual Studio 2012生成后事件-错误代码255

C# Visual Studio 2012生成后事件-错误代码255,c#,.net,visual-studio,post-build-event,C#,.net,Visual Studio,Post Build Event,以下是我试图将应用程序可执行文件复制到另一个文件夹的尝试,更改其名称: IF $(ConfigurationName) == Release ( SET DESTINATION=$(ProjectDir)Output\Distribution IF NOT EXIST "%DESTINATION%" ( MD "%DESTINATION%" ) XCOPY /Q /Y "$(TargetPath)" "%DESTINATION%" RENAME "%DESTI

以下是我试图将应用程序可执行文件复制到另一个文件夹的尝试,更改其名称:

IF $(ConfigurationName) == Release (
    SET DESTINATION=$(ProjectDir)Output\Distribution

    IF NOT EXIST "%DESTINATION%" ( MD "%DESTINATION%" )

    XCOPY /Q /Y "$(TargetPath)" "%DESTINATION%"
    RENAME "%DESTINATION%\$(TargetFileName)" "$(TargetName).Plain$(TargetExt)"
)
我已经尝试了一切使它工作,但它总是抛出错误代码255或1,这取决于。用一个简单的批处理文件运行代码就像一个符咒

您需要使用SETLOCAL EnableDelayedExpansion命令启用延迟扩展。在生成后事件的顶部执行此操作。之后,您可以使用%variable\u NAME%,而不是%variable\u NAME%来访问您的变量!变量名称!(在变量名的两侧使用感叹号,而不是在常规批处理文件中使用的百分比符号)

比如说

SETLOCAL EnableDelayedExpansion
如果$(ConfigurationName)=发布(
设置目标=$(ProjectDir)输出\分发
回显我的目的地目录是!目的地!
)
这将输出如下内容

我的目标目录是D:\Work\Projects\PBExample\Output\Distribution。

由于生成后事件命令行实际上是作为批处理文件运行的,因此您需要通过将字符加倍到%%来转义字符,如%: