How would automatically update the AssemblyFileVersion (Visual Studio, WPF C# application) to the current date, format YY.MM.DD (23.05.09) using a powershell pre build event.
I've tried this:
Powershell -Command "(Get-Content $(ProjectDir)Properties\AssemblyInfo.cs) | Foreach-Object { $_ -replace 'AssemblyFileVersion\("[\d\.]+"\)', 'AssemblyFileVersion("' + (Get-Date -Format "yy.MM.dd") + '")' } | Set-Content $(ProjectDir)Properties\AssemblyInfo.cs"
But get error:
ObjectNotFound: (C:\...AssemblyInfo.cs:String) [Get-Content], ItemNotFoundEx
FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
EDIT:
AssemblyInfo.cs was not located in Properties directory so changing it to:
$(ProjectDir)AssemblyInfo.cs)
Fixes the first error but now I get this error:
| Foreach-Object { $_ -replace 'Assemb ...
1>+ ~~~~~~~~
1> + CategoryInfo : InvalidOperation: (System.Object[]:Object[]) [], RuntimeException
1> + FullyQualifiedErrorId : BadReplaceArgument
EDIT2:
Command no error, but still don't update FileVersion.
AssebmlyFileInfo.cs:
[assembly: AssemblyFileVersion("23.05.03")].
Command:
Powershell -Command "(Get-Content $(ProjectDir)AssemblyInfo.cs) | Foreach-Object { $_ -replace 'AssemblyFileVersion\("[\d\.]+"\)', ('AssemblyFileVersion("' + (Get-Date -Format "yy.MM.dd") + '")') } | Set-Content $(ProjectDir)AssemblyInfo.cs"