Packaging projects with localized resources inside

May 27, 2011 at 7:10 AM

Hi,

I have a dll project which contains the resources to localize a web application. So we have a default Texts.resx, and several Texts.en.resx, Texts.fr.resx, Texts.de.resx, and so on. Building this project causes to have a Texts.dll in the output folder, as well as a new folder for each one of the localized resources in the project:

\bin\Release\Texts.dll
\bin\Release\en\Texts.resources.dll
\bin\Release\fr\Texts.resources.dll
\bin\Release\de\Texts.resources.dll 

When packaging this dll as a nuget package, only the main dll gets included, and all the localized ones are ignored. In this case, I ended up including all the references by hand in the .nuspec file:

 

<files>
    <file src="bin/Release/de/Texts.resources.dll" target="lib/net40/de/Texts.resources.dll" />
    <file src="bin/Release/en/Texts.resources.dll" target="lib/net40/en/Texts.resources.dll" />
    <file src="bin/Release/fr/Texts.resources.dll" target="lib/net40/fr/Texts.resources.dll" />
... </files>

In this case, I only have 1 resource file and 11 localized versions. But the main app has about 30 resource files and 30x11 = 330 localized versions... so including them by hand doesn't seem a good idea...

Is there anyway that "nuget pack" knows about this localized DLLs and include them in the package? just as MSBuild does...

Have you ever thought about it? Should this be an improvement?

Thanks,
Sergi

 

May 27, 2011 at 9:00 AM

Have you tried something along the line:

<file src="bin/Release/**/*.resources.dll" target="lib/net40" />

 That should take the right files and copy them to lib with a correct relative structure.

May 30, 2011 at 7:31 AM
TripleEmcoder wrote:

Have you tried something along the line:

<file src="bin/Release/**/*.resources.dll" target="lib/net40" />

 That should take the right files and copy them to lib with a correct relative structure.

Thanks for the tip. It worked (I should have thought about that myself... :-( )

Anyway, I still believe that localized resources are part of the assembly itself, and should be included by default in the package, the same that Nuget does with files whose Build action is "Content". 

Cheers,
Sergi

Apr 20, 2012 at 5:11 PM
sgisbert wrote:
TripleEmcoder wrote:

Have you tried something along the line:

<file src="bin/Release/**/*.resources.dll" target="lib/net40" />

 That should take the right files and copy them to lib with a correct relative structure.

Thanks for the tip. It worked (I should have thought about that myself... :-( )

Anyway, I still believe that localized resources are part of the assembly itself, and should be included by default in the package, the same that Nuget does with files whose Build action is "Content". 

Cheers,
Sergi


Exactly, Sergi, those resources should be included and Nuget still doesn't handle this well.

Oct 31, 2012 at 1:00 PM

Is this workaround still usable in version 2.1?

I have some issues trying to include resource assemblies in my package:

  1.  Using the above snippet does not add the files and no message is displayed
  2.  Specifying an absolute path to the satellite assembly (just for testing purpose) results in a package error (file not found).
Nov 6, 2012 at 11:02 PM

Hello Blade,

I just tried the original scenario in NuGet 2.1, and was unable to reproduce the problem.  I could verify that the resource DLLs were getting added to the .nupkg as content files.  Since the resource files aren't directly referenced by project code, this solution should work in virtually all cases.

Let me know if you're seeing otherwise.  I'm very interested in problems generating NuGet packages.

Thanks,
Clay

Nov 7, 2012 at 1:33 PM

Thanks for your feedback.

Just to be sure, I created a simple project (NuGetTest), containing some localized resources and a dummy class.

Then I let nuget generate the spec file, and modified it according to the information from this thread, to include satellite assemblies:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>Simple test to try to include localized resource assemblies.</releaseNotes>
    <copyright>Copyright 2012</copyright>
    <tags>test sample satellite assembly resource localized</tags>
  </metadata>
  <files>
    <file src="bin/Debug/**/NuGetTest.resources.dll"
          target="lib/net40"/>
  </files>
</package>

(I even tried omitting the specific file name, using * wildcard instead).

Finally, I generate the package. Despite the inclusion, the resource files (with proper target) are not included (I verified both using NuGet Package Explorer and browsing the package as a zip file).

I am invoking spec/pack commands directly inside the VS powershell, the NuGet version is 2.1.31022.9038.

I am probably doing a silly mistake, but I cannot figure out which...

You can download the complete (albeit simple) sample project from here.

Nov 7, 2012 at 1:43 PM
i can confirm your observations, no matter what we do or set the resources or resource DLLs do not get included in the package. I followed exactly the same steps.

Marko

From: BladeWise
Sent: 7.11.2012 15:33
To: Marko Hrovatič
Subject: Re: Packaging projects with localized resources inside [nuget:259206]

From: BladeWise

Thanks for your feedback.

Just to be sure, I created a simple project (NuGetTest), containing some localized resources and a dummy class.

Then I let nuget generate the spec file, and modified it according to the information from this thread, to include satellite assemblies:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>Simple test to try to include localized resource assemblies.</releaseNotes>
    <copyright>Copyright 2012</copyright>
    <tags>test sample satellite assembly resource localized</tags>
  </metadata>
  <files>
    <file src="bin/Debug/**/NuGetTest.resources.dll"
          target="lib/net40"/>
  </files>
</package>

(I even tried omitting the specific file name, using * wildcard instead).

Finally, I generate the package. Despite the inclusion, the resource files (with proper target) are not included (I verified both using NuGet Package Explorer and browsing the package as a zip file).

I am invoking spec/pack commands directly inside the VS powershell, the NuGet version is 2.1.31022.9038.

I am probably doing a silly mistake, but I cannot figure out which...

You can download the complete (albeit simple) sample project from here.

Developer
Nov 7, 2012 at 4:22 PM

My guess is that it's the forward slash character in the path specification for the files node. That bug is being addressed, but switch it to be a backward slash for the time being.

Nov 7, 2012 at 9:52 PM
Edited Nov 7, 2012 at 9:52 PM

@pranavkm: I can confirm that using a backward slash fixes this kind of issue. Thanks a lot for the tip.

Nov 26, 2012 at 1:44 PM

Thanks pranavkm, your solution did indeed help, I just wish this was mentioned somewhere before like in Release Notes. It's quite possible this backslash fix was working for months but we didn't know it and this topic has been open since May 2011 (the problem goes back even further).

Nov 26, 2012 at 1:45 PM

Actually @pranavkm what's the Bug ID, so we can track it?

Developer
Nov 26, 2012 at 4:07 PM

http://nuget.codeplex.com/workitem/2767

Since it says it is fixed for 2.3, you should be able to pick up the exe from the master branch and see if it solves your issue.