I have a post build event which is writing to a text file. It is working fine when I am building the project from Visual Studio. But when I am using msbuild.exe the Post build event is not writing to the file. I am using msbuild with following parameters:
msbuild.exe TestProj.Web.csproj /p:Configuration=Release /p:OutDir=C:\TestProj\bin\ /p:WebProjectOutputDir=C:\TestProj\ /p:DebugSymbols=false /p:DebugType=None
The post build event looks like:
<PropertyGroup Condition="'$(BUILD_NUMBER)'==''">
<COMPUTERNAME>None</COMPUTERNAME>
<BRANCH>None</BRANCH>
<BUILD_NUMBER>None</BUILD_NUMBER>
</PropertyGroup>
<Target Name="AfterBuild">
<WriteLinesToFile File="$(ProjectDir)$(OutputPath)\VersionInfo.txt" Overwrite="true" Lines="Project
Created On $(COMPUTERNAME)
Branch is $(BRANCH)
Version Is $(BUILD_NUMBER)" />
</Target>
To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.
To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2019, or install the . NET SDK. If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2022, it's installed under the Visual Studio installation folder.
MSBuild, or the Microsoft Build Engine platform, is a collection of tools used to build applications using Microsoft and third-party compilers like Intel and NVIDIA CUDA.
To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.
I have got it fixed by changing the Task to
<WriteLinesToFile File="$(OutDir)\VersionInfo.txt" ...... />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With