Closed GabrielSandor closed 3 years ago
Did you try BeforeTargets="BeforeBuild"
instead of PrepareForBuild
?
Otherwise, I'd call dotnet restore in your CI steps, before calling dotnet build.
@jeremyVignelles I just did, and it seems to work even without the explicit dotnet restore
instruction. Thanks! I'll do some more testing to make sure the initial problem no longer appears.
As for the CI build, that's not a problem because it has an explicit dotnet restore
step before the build, the problem only arose when building from Visual Studio.
If I remember correctly, dotnet build
performs a dotnet restore
, but BeforeTargets="PrepareForBuild"
executes before the restore could happen, while BeforeBuild
is before the actual compilation (and after the restore).
I am generating Swagger clients using NSwag.MSBuild as a pre-build step in a C# project in the following manner:
The csproj is in the new SDK format (
<Project Sdk="Microsoft.NET.Sdk">
) and it targetsnet452
.The problem is that, in a newly checked out solution where the NSwag.MSBuild NuGet package does not exist yet on the local machine, the build fails because it can't find the executable. I work around this by commenting the pre-build step above in the csproj file, build the solution, then re-instate the build step. This is unwanted manual work so i tried to avoid it by adding a
dotnet restore
step right before calling the exe, like this:This does the trick and the build doesn't fail anymore, however i noticed that
"!Exists('$(NSwagExe)')"
always returnstrue
, which means thatdotnet restore
will be unnecessarily executed even when the NuGet package with the executable is already downloaded. Is there a way to avoid this? Alternatively, is there a better workaround to avoid the pre-build failure altogether?