Open geidans opened 4 years ago
I'm not sure that PrepareForBuild
is called only once in the build process. I dropped the BeforeTargets=..
and usually run dotnet build /t:NSwag
as part of my build pipeline, because my spec doesn't change very often.
I have this in a build.ps1:
& dotnet build -t:NSwag "Project.csproj"
if (-not $?)
{
throw 'Error generating NSwag'
}
$GitStatusOutput = (git status --porcelain) | Out-String
if ( $GitStatusOutput -ne "" )
{
throw 'There are uncommited changes in your repository, please commit your changes and run this command again'
}
That way, if I forgot to update the NSwag client classes, I am notified that something went wrong, and I need to test locally.
It appeared that problem is due to parallel builds in Visual Studio. Having played with dependencies did not help. I have now disabled parallel build and all seem to be working fine.
It appears added target NSwag executes 2 times (in parallel) during build.
I have added the following section to csproj project file:
The log output:
And it fails here:
2>C:\Program Files\dotnet\sdk\3.1.201\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3088: Could not read state file "obj\Debug\netcoreapp3.1\XXXXXXXX.csprojAssemblyReference.cache". The process cannot access the file 'XXXXXXXXXX\obj\Debug\netcoreapp3.1\XXXXXXXXXX.csprojAssemblyReference.cache' because it is being used by another process. [XXXXXXXXXXXXXXXXX.csproj]
When running build in VS 2019 it appear to be invoked 3 times, resulting in intermittent failure:
There is no pattern on when it fails or when it succedes.