I am executing a T4 template using a pre-build event with the following script added in the Properties > Build Events > Pre-build event command line:
set textTemplatingPath="%CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe"
if %textTemplatingPath%=="\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe" set textTemplatingPath="%CommonProgramFiles%\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe"
%textTemplatingPath% "$(ProjectDir)AssemblyFileVersion.tt"
While building the solution the above script is working fine and I am able to get output from T4 template file. But I am looking to execute this script while publishing the WPF application instead of building the solution.
I have moved the script in the batch file and put a reference of that batch file inside .csproj
file.
<Target Name="BeforePublish" BeforeTargets="MSDeployPublish">
<Exec Command="$(SolutionDir)v1.bat" />
</Target>
While I am publishing the project, I am getting following error.
The command "xx\v1.bat" exited with code 9009
The file exists in the location but I am not able to figure out if there is an issue with the script or the way I am trying to achieve the result.
Edit:
When I checked the Output window, it was due to the space in one of the directories (Visual Studio 2015 in my case) included in the path. For now, I have placed v1.bat inside D: folder.
<Target Name="BeforePublish" BeforeTargets="MSDeployPublish">
<Exec Command="D\v1.bat" />
</Target>
Now when I am trying to publish the app, it shows me the following error.
The command "D:\v1.bat" exited with code 1
and the Output window is showing "The system cannot find the path specified".
It seems like the problem is with the variables used in the script and not in the path of the v1.bat file defined in the Target
above because when I am simply keeping echo StackOverflow
in the batch file it is showing the text and successfully publishing the app. To me, it seems like the way I used the script in the pre-build command line in Visual Studio IDE would be quite different the way if I need to run the same script from batch file.
Thanks