Reputation: 151
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
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