How to create a nuget file with both the Release and Debug configurations using msbuild in Azure Devops
I am afraid you could not create a nuget file with both the Release and Debug configurations using msbuild at this moment.
That because NuGet package will normally hold just a single set of assemblies for a particular target framework. It is not really designed to ship a debug and release version.
If we use nuget, we could use a custom MSBuild .targets
file in the .nuspec
that has its own references and configuration information:
Check this thread for some more details.
But, if you want use the MSBuild, we could not specify the dlls file driectly, we have to create two packages for debug
and release
, then we add a custom MSBuild .targets
file in the project file with the properties <Pack>true</Pack>
and <PackagePath>build\</PackagePath>
, like following:
<ItemGroup>
<None Include="build\*.targets" Pack="True" PackagePath="build\" />
</ItemGroup>
In this case, the .targets
file will be packed in the build folder, which will imported into the nuget installation project:
Check this thread for some more details.
Besides, in the .targets
file, you could use a Choose/When
to select the PackageReference
for debug
and release
:
<Choose>
<When Condition=" '$(Configuration)'=='debug' ">
<ItemGroup>
<PackageReference Include="MyRefDebug">
<Version>1.0</Version>
</PackageReference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="MyRefRelease">
<Version>2.0</Version>
</PackageReference>
</ItemGroup>
</Otherwise>
</Choose>
Check the github ticket for some more details.
Hope this helps.