6

NuGet excludes anything that ends ".Resources.dll" when determining which dlls in a package should be added as assembly references. This is designed to exclude the localised satellite assemblies, but it means it is tricky to add a reference if you have a DLL that is called MyCompany.Resources.dll.

Are there any good workarounds for this?

Community
  • 1
  • 1
Joe Taylor
  • 2,145
  • 1
  • 19
  • 35

2 Answers2

6

I worked around this for now by following an example at https://nuget.codeplex.com/workitem/1644, with some modifications.

I added a check for Website projects because they don't support the 'Add' method.

I added this after the metadata element in my nuspec file. (Probably only necessary if not you're using the includereferencedprojects option available in NuGet 2.5)

<files>
  <file src="bin\Release\Foo.Resources.dll" target="lib\net40" />
  <file src="bin\Release\Foo.Resources.pdb" target="lib\net40" />
  <file src="tools\*" target="tools" />
</files>

And then added these two files to a new tools folders in my project directory. (Note the fix to the way DLL path is passed to the References.Add method, compared to the codeplex example)

Install.ps1

param($installPath, $toolsPath, $package, $project)
$resourcesDll = Join-Path $installPath "lib\net40\Foo.Resources.dll"
Write-Host "Adding resources DLL from " $resourcesDll

if ($project.Kind -eq "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") {
    $project.Object.References.AddFromFile($resourcesDll)
} else {    
    $project.Object.References.Add($resourcesDll)
}

Uninstall.ps1

param($installPath, $toolsPath, $package, $project)

Write-Host "Removing Foo.Resources reference"
$project.Object.References | where { $_.Name -eq 'Foo.Resources' } | foreach { $_.Remove() }
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
Joe Taylor
  • 2,145
  • 1
  • 19
  • 35
  • Thanks! this really helped us. it'd been driving me crazy why my blah.resources.dll wouldn't add a reference. – Sam Holder Oct 24 '14 at 14:08
  • It seems that this workaround means that the package can't be updated from the command line any more and powershell commands are not run from the command line update. Grrrr... – Sam Holder Feb 16 '15 at 10:09
1

This fork of NuGet has changes that would address this, however given the additional complexity I'm not sure it will ever make it into master: https://nuget.codeplex.com/SourceControl/network/forks/jjgonzalez/1644/contribution/5459

Joe Taylor
  • 2,145
  • 1
  • 19
  • 35