2

I'm not sure if I'm missing something obvious or if I just don't get the NuGet resource policy. Resources (.resource.dll) are excluded by default on package creation, according to https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package:

Resources are, in fact, a special case. When a package is installed into a project, NuGet automatically adds assembly references to the package's DLLs, excluding those that are named .resources.dll because they are assumed to be localized satellite assemblies (see Creating localized packages). For this reason, avoid using .resources.dll for files that otherwise contain essential package code.

However, the document referenced in the snippet above (https://learn.microsoft.com/en-us/nuget/create-packages/creating-localized-packages) states two ways of creating localized NuGet packages:

There are two ways to create localized versions of a library:

  1. Include all localized resources assemblies in a single package.
  2. Create separate localized satellite packages by following a strict set of conventions.

Both methods have their advantages and disadvantages, as described in the following sections.

While I get the advantages and disadvantages of the two approaches, I don't understand why there is no option to simply include resource files when creating a NuGet package from a .csproj project (i.e. use option 1.).

My goal is to be able to do:

  • Create/update/complement a library project foo.csproj with localized resources and build it
  • Create a NuGet package out of it via nuget.exe pack foo.csproj <Maybe some Parameters>
  • Add/update the newly created NuGet package to another project bar.csproj and have foo.csproj's resources included automatically

To me that sounds like such a common requirement that it's hard for me to imagine that this isn't possible. What am I missing?

Community
  • 1
  • 1
Hannes
  • 273
  • 3
  • 14

1 Answers1

0

Although I also miss one simple checkbox in VS project properties "Packages" tab, there is a simple way to add localized resources to your nuget package. Just add for each localized resource a "Content Include" to your .csproj file.

Example for "en" localized resources:

<ItemGroup>
   <Content Include="$(OutputPath)\$(TargetFramework)\en\$(TargetName).resources.dll">
      <Pack>true</Pack>
      <PackagePath>lib\en\$(TargetFramework)</PackagePath>
  </Content>
</ItemGroup>

Source: https://stackoverflow.com/a/64209770

I think the reason not having an out of the box "include localized resources" checkbox in VS Packages tab is, because you might want to apply Option 1 or Option 2 depending on with what disadvantages you can live with.