3

I'm trying to build a project with NSwagger installed. Here is my .csporj configuration:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\NSwag.MSBuild.11.15.3\build\NSwag.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NSwag.MSBuild.11.15.3\build\NSwag.MSBuild.props'))" />
</Target>

<Target Name="BeforeBuild">
    <Exec Command="$(NSwagExe) run $(SolutionDir)webapi.nswag" />
</Target>

Error :

ValidateSolutionConfiguration: Building solution configuration "Debug|Any CPU". Project "C:\agent_work\8\s\Web\CSU.Marketplace.Web.sln" (1) is building "C:\agent_work\8\s\Web\CSU.Marketplace.Web\CSU.Marketplace.Web.csproj" (2) on node 1 (default targets). BeforeBuild: run C:\agent_work\8\s\Web\webapi.nswag 'run' is not recognized as an internal or external command, operable program or batch file. Web\CSU.Marketplace.Web\CSU.Marketplace.Web.csproj(942,5): Error MSB3073: The command " run C:\agent_work\8\s\Web\webapi.nswag" exited with code 9009.

C B
  • 1,677
  • 6
  • 18
  • 20

1 Answers1

3

The project file does not import the NSwag build tasks. Therefore at build time, $(NSwagExe) expands to an empty string, and msbuild tries to run the rest of the command:

run C:\agent_work\8\s\Web\webapi.nswag

Add something like this:

<ItemGroup>
    <PackageReference Include="NSwag.MSBuild" Version="11.12.9" />
</ItemGroup>
Frank Hagenson
  • 953
  • 8
  • 17