0

I have a nuspec file that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>MyDll.Service</id>
    <version>1.0.0</version>
    <title>MyDll.Service</title>
    <authors>MyDll</authors>
    <owners>MyDll</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <copyright>Copyright © 2017</copyright>
    <dependencies>
      <dependency id="SomeDll" version="1.0.0" />
    </dependencies>
    <references>
      <reference file="MyDll.Service.Context.dll" />
    </references>
  </metadata>
  <files>
    <file src="..\..\Folder\MyDll.Service.Context\bin\Release\MyDll.Service.Context.dll" target="lib\net452"/>
    <file src="..\..\Folder\MyDll.Service\bin\Release\MyDll.Service.dll" target="lib\net452"/>
  </files>
</package>

This generates me a nuget package that contains 2 dlls. The project itself only references MyDll.Service.Context.dll (which is exactly what I want).

I am using injection to insert the MyDll.Service.dll wherever the classes for MyDll.Service.Context.dll are mentioned. My only problem is that when I build, the dll MyDll.Service.dll is not pulled into the bin folder of the main project. Only the MyDll.Service.Context.dll is. This makes sense because I only reference the context dll.

My question, how can I get MyDll.Service.dll pulled into the bin folder upon building and publishing the project, without having to reference that dll in the project?

EDIT:

As per suggestion in the comments I tried to do this with MSBuild. I changed my nuspec to the following:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>MyDll.Service</id>
    <version>1.0.0</version>
    <title>MyDll.Service</title>
    <authors>MyDll</authors>
    <owners>MyDll</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <copyright>Copyright © 2017</copyright>
    <dependencies>
      <dependency id="SomeDll" version="1.0.0" />
    </dependencies>
    <references>
      <reference file="MyDll.Service.Context.dll" />
    </references>
  </metadata>
  <files>
    <file src="..\..\Folder\MyDll.Service.Context\bin\Release\MyDll.Service.Context.dll" target="lib\net452"/>
    <file src="..\..\Folder\MyDll.Service\bin\Release\MyDll.Service.dll" target="lib\net452"/>
  </files>
</package>

Unfortunately, all that did was cause my MyDll.Service.dll dll to show up twice in my package, once in the build folder and once in the lib folder. However, upon build the dll was still not in the folder.

Bagzli
  • 6,254
  • 17
  • 80
  • 163
  • I would probably look at using an MSBuild target that you ship with your NuGet package similar to what is described here - http://stackoverflow.com/questions/33016850/nuget-package-with-legacy-dlls/33018794#33018794 – Matt Ward Apr 17 '17 at 11:06
  • @MattWard what is .targets? Is that a property inside nuspec file or is it a file on its own? What is this practice called, as in what can I search to find online a guide on how to get this done? I looked at that SO answer but its very vague. – Bagzli Apr 17 '17 at 16:05
  • It is an MSBuild file which you can include in your NuGet package - https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package – Matt Ward Apr 17 '17 at 16:09
  • @MattWard Thank you for that. I have to be honest and admit I am still quite a bit lost as to how this works. Tried googling for more but came up short. Do you happen to have an example somewhere I can look up? What I am mostly confused about is that the article mentions props and targets and it doesn't mention anywhere how I link my dll's that I want. – Bagzli Apr 17 '17 at 19:01
  • 1
    There is an example in the original stackoverflow post. It will copy a file to the output directory when building. If you need to do something else I would just get it working in your project first and then see how/what is created for that file and then basically copy it to the .targets file that will be part of your NuGet package. – Matt Ward Apr 18 '17 at 13:02

0 Answers0