0

I need to create a nuget file which contains both the release and debug versions of my dll. I need to be able to do this in Azure Devops using the MSBuild task.

I'm using MSBuild due to the bug in the NuGet Task where if you use the new packagereference and projectreference it doesn't do the dependency information correctly.

I have tried doing two builds one in debug and one in release, and then having the release one do a pack. This still only gave me one file. I also tried using a nuspec file to try to tell it to grab both files, but this still only resulted in one file in the package.

civbaron
  • 3
  • 1

1 Answers1

0

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135