Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Building with OpenApi generation
kkraus
#1 Posted : Monday, December 9, 2024 11:41:25 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/9/2024(UTC)
Posts: 2
Location: Austria

Was thanked: 1 time(s) in 1 post(s)
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:

Quote:

NCrunch: If you are experiencing problems in getting this project to build, have a look at https://www.ncrunch.net/...ng_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:

Quote:

<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
Remco
#2 Posted : Monday, December 9, 2024 10:37:01 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
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?
kkraus
#3 Posted : Tuesday, December 10, 2024 8:45:30 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/9/2024(UTC)
Posts: 2
Location: Austria

Was thanked: 1 time(s) in 1 post(s)
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
1 user thanked kkraus for this useful post.
Remco on 12/11/2024(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.047 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download