Jens B
Jens B

Reputation: 151

Write a text file on VS Built

I want to write a text file in a VS build that contains a newly created guid. The writing of the file works, but how do I get a guid into it?

Like this (this dont work):

Guid x = System.Guid.NewGuid();
echo x >> file.txt

Upvotes: 0

Views: 596

Answers (1)

JL0PD
JL0PD

Reputation: 4528

Add this task to your csproj file. This will create new guid and save it to guid.txt using WriteLinesToFile task. It also supports different formats of result with ToString

  <Target Name="SaveGuidToSomeFile" BeforeTargets="BeforeBuild">
    <WriteLinesToFile File="guid.txt" Lines="$([System.Guid]::NewGuid().ToString('d'))" Overwrite="true" />
  </Target>

Overwrite="true" required to overwrite file instead of appending which is default

Upvotes: 2

Related Questions