Nswag: MSBuild fails with System.InvalidOperationException: Project outputs could not be located

Created on 1 Jul 2019  路  4Comments  路  Source: RicoSuter/NSwag

Build log:

.NET Core SDK v2.2.300 dotnet.exe publish ProjectName.sln --configuration Test
Executing file 'application.nswag' with variables 'Configuration=Test,OutDir=bin\Test\netcoreapp2.2\'...
System.InvalidOperationException: Project outputs could not be located in 'C:\BuildAgent\work\90f916f3df1af0df\ProjectName\bin\Debug\netcoreapp2.2\'. Ensure that the project has been built.

It's always Debug in path, no matter what _Configuration_ was passed
Using the recommended configuration from https://github.com/RicoSuter/NSwag/wiki/MSBuild.

See csproj (partial):

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <Configurations>Debug;Test;Release</Configurations>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DefineConstants>TRACE;DEBUG</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Test|AnyCPU'">
    <DefineConstants>TRACE;TEST</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DefineConstants>TRACE;RELEASE</DefineConstants>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NSwag.AspNetCore" Version="13.0.3" />
    <PackageReference Include="NSwag.MSBuild" Version="13.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
...
  <Target Name="NSwag" AfterTargets="Build">
    <Copy SourceFiles="@(ReferencePath)" DestinationFolder="$(OutDir)References" />
    <Exec Command="$(NSwagExe_Core22) run application.nswag /variables:Configuration=$(Configuration),OutDir=$(OutDir)" />
    <RemoveDir Directories="$(OutDir)References" />
  </Target>
</Project>

Most helpful comment

Did you also use the configuration variable in the config file?

{
  "runtime": "NetCore22",
  "defaultVariables": null,
  "documentGenerator": {
    "aspNetCoreToOpenApi": {
      "project": "NSwag.Sample.NETCore22.csproj",
      "msBuildProjectExtensionsPath": null,
      "configuration": "$(Configuration)",

All 4 comments

Did you also use the configuration variable in the config file?

{
  "runtime": "NetCore22",
  "defaultVariables": null,
  "documentGenerator": {
    "aspNetCoreToOpenApi": {
      "project": "NSwag.Sample.NETCore22.csproj",
      "msBuildProjectExtensionsPath": null,
      "configuration": "$(Configuration)",

Had "configuration": null. Now works, thank you very much!

Hi @RicoSuter - With .Net core 3.1, the path to the project output is ..\project-name\bin*x64*\Debug. The aspnetcore2openapi seems to refer to \bin\debug and is missing the x64 in the path. Any way we can specify that? Thanks!

solved this by removing the x64 from the and re-checking the checkbox on Project properties UI. It moved it to different PropertyGroup.

Was this page helpful?
0 / 5 - 0 ratings