I've written a PowerShell script to build several .net solutions one after the other. It simply makes several calls to tfget (to get latest) followed by calls to devenv.exe (to build the .sln files).
Here's the code:
tfget -item $SolutionPath -overwrite -recurse -ev +errors
...
$out = invoke-expression "devenv.com /rebuild debug $SolutionPath"
Almost every time I run the script one of the solutions fails to build and I get an error from CSC.exe (?) saying:
error CS1606: Assembly signing failed; output may not be signed -- The process cannot access the file because it is being used by another process.
This happens even though I've closed all instances of Visual Studio holding these solutions and I've none of their exes running on my machine.
A similar batch file that I've written works just fine. It's only PowerShell that complains about the file being used by another process.
How can I avoid having this happen? Are there any better examples out there of building .net solutions through PowerShell?
Don't use invoke-expression. Just call devenv.exe directly on the SLN file (or for that matter just use MSBuild.exe unless you have setup or other unsupported project types). One of the beauties of using a shell scripting language is that they are designed to work with console exes rather seamlessly. We do this all the time in PowerShell scripts:
msbuild.exe "R:\Source\Foo.sln" /t:build /p:Configuration=Debug `
/v:detailed 2>&1 | Out-String -stream -width 1024 > $DebugBuildLogFile
We run the output through Out-String so that the log file output doesn't wrap at 80 or 120 chars (default width of the console that runs the script).
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