2

Hi I would like to know how I would go about this scenario:

  • I have a .Net PCL library with Debug and Release configurations
  • I want to create a nuget package out of it which holds both configuration outputs.
  • I want to use VSTS as the symbols server for the Debug build.
  • I want to switch to the correct assembly using selected configuration when having my package installed.

I followed this answer but I never got the targets file integrated into the consuming csproj file.
The version is set to a fixed number there?

This is my nuspec file contents:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>My.Assembly</id>
    <version>1.0.0.0</version>
    <title>A Library</title>
    <authors>Me</authors>
    <owners>Me</owners>
    <!-- <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl> -->
    <!-- <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl> -->
    <!-- <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl> -->
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>A Library</description>
    <releaseNotes>Some release notes.</releaseNotes>
    <copyright>Copyright 2018</copyright>
    <!-- <tags>Tag1 Tag2</tags> -->
  </metadata>
      <files>
        <file src="bin\**" target="lib" />
        <file src="*.targets" target="build" />
    </files>
</package>

What is advised to do here?

(using NuGet Version: 4.4.1.4656)

Community
  • 1
  • 1
grmbl
  • 2,514
  • 4
  • 29
  • 54
  • I have updated my answer, you can check if it help you. AFAIK, a 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. Normally you do not publish a debug and a separate release version of your application to end users. if you persist, you can check the workaround below. – Leo Liu Jan 18 '18 at 09:20

1 Answers1

1

but I never got the targets file integrated into the consuming csproj file.

Not sure why you could not got the targets file integrated into the consuming csproj file, if .targets file is under your build folder in your nuget package, then when you add this nuget package to the project, the .targets file will be integrated into the consuming csproj file.

The first thing is make sure the nuget package is correct:

This is my .nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>My.Assembly</id>
    <version>1.0.0</version>
    <authors>Admin</authors>
    <owners>Admin</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2018</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
  <files>
    <file src="bin\**" target="lib" />
    <file src="*.targets" target="build" />
  </files>
</package>

You should make sure that .targets file is in the same folder as your .nuspec file, in this case, this command src="*.targets" can include the .targets file into the nuget package.

Note: The name of the .targets file must match the ID of your package, for your situation, the name of .targets must be My.Assembly.targets.

After pack the .nuspec, you will get following structure nuget package:

enter image description here

Then install this package to your project, after installation, unload the project, edit the project file, in the .csproj file, following code would be imported:

<Import Project="..\packages\My.Assembly.1.0.0\build\My.Assembly.targets" Condition="Exists('..\packages\My.Assembly.1.0.0\build\My.Assembly.targets')" />

Now, the .targets file integrate into the consuming csproj file.

In addition, there is an issue for this solution, because the dlls in lib folder will be automatically added as references creating the following in the project file:

<Reference Include="My.Assembly, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\packages\My.Assembly.1.0.0\lib\Release\My.Assembly.dll</HintPath>
</Reference>

So we could not set dll file in the lib folder, we could set the dll file in to the tools folder, then add a target in the .targets file to copy the dll file from tools folder to lib folder before build the project:

  <files>
    <file src="bin\Debug\My.Assembly.dll" target="lib\net\$(Configuration)\My.Assembly.dll" />  
    <file src="bin\**" target="tools" />
    <file src="*.targets" target="build" />
  </files>

For the detailed info you can refer to the Arie R`s answer in the thread which you are referencing:

How to create a nuget package with both release and debug dll's using nuget package explorer?

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks for your Answer Leo! I already managed to get it working. I didn't know that assemblies from lib where the ones added as reference in the csproj, thanks. But I think content is a better place then. I'm struggling with the target frameworks now... I'll update my question when I make more progress. – grmbl Jan 18 '18 at 09:43
  • @grmbl, could you post your solution as a answer and accept it after SO limitation? This can be beneficial to other community members reading this thread. Thanks. – Leo Liu Jan 19 '18 at 09:36