Build/Test Issues

Building with OpenApi generation

Started by kkraus on 3,495 views

Hello,

since dotnet9 is deprecating the old way to create OpenApi documents the recommended way is to add a package reference to

<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.0">

Everything builds via dotnet and visual studio but building with NCrunch results in this error:


NCrunch: If you are experiencing problems in getting this project to build, have a look at https://www.ncrunch.net/documentation/troubleshooting_project-build-issues
..\..\..\..\..\Users\xxx\.nuget\packages\microsoft.extensions.apidescription.server\9.0.0\build\Microsoft.Extensions.ApiDescription.Server.targets (68, 5): Error:
..\..\..\..\..\Users\xxx\.nuget\packages\microsoft.extensions.apidescription.server\9.0.0\build\Microsoft.Extensions.ApiDescription.Server.targets (68, 5): An assembly specified in the application dependencies manifest (CustomField.Change.Service.deps.json) was not found:
..\..\..\..\..\Users\xxx\.nuget\packages\microsoft.extensions.apidescription.server\9.0.0\build\Microsoft.Extensions.ApiDescription.Server.targets (68, 5): package: 'CustomField.EventDefinitions', version: '1.0.0.0'
..\..\..\..\..\Users\xxx\.nuget\packages\microsoft.extensions.apidescription.server\9.0.0\build\Microsoft.Extensions.ApiDescription.Server.targets (68, 5): path: 'CustomField.EventDefinitions.dll'
..\..\..\..\..\Users\xxx\.nuget\packages\microsoft.extensions.apidescription.server\9.0.0\build\Microsoft.Extensions.ApiDescription.Server.targets (68, 5): The command "dotnet "C:\Users\xxx\.nuget\packages\microsoft.extensions.apidescription.server\9.0.0\build\../tools/dotnet-getdocument.dll" --assembly "C:\Users\xxx\AppData\Local\NCrunch\39400\8\src\Change\CustomField.Change.Service\bin\Debug\net9.0\CustomField.Change.Service.dll" --file-list "obj\CustomField.Change.Service.OpenApiFiles.cache" --framework ".NETCoreApp,Version=v9.0" --output "C:\Users\xxx\AppData\Local\NCrunch\39400\8\src\Change\CustomField.Change.Service\obj" --project "CustomField.Change.Service" --assets-file "C:\Users\xxx\AppData\Local\NCrunch\39400\8\src\Change\CustomField.Change.Service\obj\project.assets.json" --platform "AnyCPU" " exited with code -2147450740.



In a global build.properties I have this:


<Choose>
<When Condition=" $(MSBuildProjectName.EndsWith('.Service')) And !($(MSBuildProjectName.EndsWith('.Query.Service')))
And '$(NCrunch)' != '1'">

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<OpenApiDocumentsDirectory>$(SolutionDir)/results/swagger</OpenApiDocumentsDirectory>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</When>
</Choose>



I am using NCrunch 5.11.0.1

Unfortunately even And '$(NCrunch)' != '1' doesnt help.
Any ideas?
Klemens

Edited

Hi, thanks for sharing this issue.

The root problem here probably comes from the package restore step, which is done by VS without the $(NCrunch) property active. This then causes the PackageReference to bleed into the project.assets.json file which is shared between between both VS and NCrunch. The manner in which VS uses project.assets.json prevents us from making package references conditional under NCrunch.

A better way is often to try and shut down the target in the referenced package by using a property. The 'GenerateDocumentationFile' property looks like it might do this. If you get rid of the NCrunch condition on the Choose statement and instead do this:
<GenerateDocumentationFile Condition="'$(NCrunch)' != '1'">true</GenerateDocumentationFile>
<GenerateDocumentationFile Condition="'$(NCrunch)' == '1'">false</GenerateDocumentationFile>

.. Does it resolve the problem?
Hello!

Thanks for the response!
I got it to work with a similar approach and using this:

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<OpenApiGenerateDocuments Condition="'$(NCrunch)' == '1'">false</OpenApiGenerateDocuments>

<OpenApiDocumentsDirectory>$(SolutionDir)/results/swagger</OpenApiDocumentsDirectory>
</PropertyGroup>

The GenerateDocumentationFile is just for the xml documentation so it doesnt affect the open api builds. Like this it is just disabled for NCrunch, otherwise its automatically enabled.

Thanks again,
Klemens

Post a reply

Log in to reply.