7

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&#xD;&#xA;Created On $(COMPUTERNAME)&#xD;&#xA;Branch is $(BRANCH)&#xD;&#xA;Version Is $(BUILD_NUMBER)" />
  </Target>
6
  • 3
    can you run your msbuild.exe with /verbosity:diagnostic to see if the logs provide you some details? or replace the writetofile task with a console output to confirm that it is being fired. Commented Feb 21, 2013 at 10:01
  • Yes The Task Performance Summary shows that WriteLinesToFile is fired. Commented Feb 21, 2013 at 10:07
  • In that case your post build event is fired. just that the writelinestofile is not working as expected? Commented Feb 21, 2013 at 10:11
  • Well it looks like that the WriteLineToFile is writing to the file, but file is not being copied back to the output folder. Or may be the WriteLinesToFiles is writing to a wrong file location. Commented Feb 21, 2013 at 10:15
  • permissions? file locked? debug debug debug Commented Feb 21, 2013 at 10:20

1 Answer 1

4

I have got it fixed by changing the Task to

<WriteLinesToFile File="$(OutDir)\VersionInfo.txt" ...... />
Sign up to request clarification or add additional context in comments.

2 Comments

<ConvertToAbsolutePath Paths="..\"> <!-- Some relative path here --> <Output TaskParameter="AbsolutePaths" PropertyName="MyAbsolutionPathProperty"/> </ConvertToAbsolutePath> <Message Text="'MyAbsolutionPathProperty' = '$(MyAbsolutionPathProperty)'" />
When in doubt, you can convert a relative path (or a value in a variable) to an absolute path, and then show it. It'll show the full path for where its trying to write.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.