How to NuGet uncompiled Resx files?

Aug 18, 2011 at 1:03 AM

I have a need to deliver a package of Resx files before they are compiled. Is there a way for NuGet to coordinate the installation of these resx files into a project properly and include their designer file?

I notice that they are included properly into the project however none of this wiring up is performed. Am I going to have to script this into my install scripts?

Aug 18, 2011 at 4:10 AM

We don’t have built-in support for this. You’ll have to script this.

The reason why we haven’t added a way to do this in our NuSpec is we’re trying to keep anything overly specific to VS from creeping into the nuspec format because we have some scenarios where NuGet is used outside of Visual Studio.

However, this seems like a case where we might be able to do the hookup by convention as long as we can reliably do the hookup in the correct cases and don’t do it in cases where it’s not wanted.

Anyone want to take a crack at defining the rules for such a hookup?

Aug 18, 2011 at 8:49 AM

I have a script sample I will be able to post that demonstrates connecting the resx to its designer file within the csproj file. However, there is an issue that I am seeing with the designer file itself that is imported. It has its originating project namespace in it. This doesn't cause a compile issue, but it causes a run-time issue where it cannot resolve the name for some reason. I can have more details tomorrow on this.

Aug 18, 2011 at 5:18 PM

We support source file transforms exactly for this case.

From the docs:

Source Code Transformations

You can specify changes to make in source code that is copied to the project by appending .pp to a source code file name. You can then embed variables in the source code that are replaced with values appropriate to the project during installation. For example, if you put namespace $rootnamespace$ in a source-code file and append .pp to the name, the code becomes namespace TargetProject when the file is installed in a target project whose root namespace is TargetProject. In the target project, the file no longer has the .pp extension.

Aug 18, 2011 at 6:31 PM
Edited Aug 18, 2011 at 6:31 PM

Yes I read this documentation before asking the question. Unfortunately this file is a "generated" file as all designer files are. Otherwise this would not be an issue.

It is suggested against modifications because at anytime VS needs to, it will modify this files content rendering everything void.

// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>

I am investigating the error that is thrown to see if there is a way around it and will post more about what I find.



Could not find any resources appropriate for the specified culture or the neutral culture.  
Make sure "BaseProject.Resources.Views.AccountMessaging.AccountMessaging.resources" was correctly embedded or 
linked into assembly "IntegrationTests" at compile time, or that all the satellite assemblies required are 
loadable and fully signed.

Aug 18, 2011 at 6:46 PM

Sure, but if you include the file in your package, and your script hooks it up, VS should take over the file afterwards. Or, you need your script to cause the file to be generated. I think that means changing the “tool type?” for it. Ebbo probably knows more than I do on that. ;)

Aug 18, 2011 at 6:50 PM

Absolutely. I have my script currently modifying the csproj file so that the resx files have a set of custom properties.

      <LastGenOutput>" + $LastGenFile + "</LastGenOutput>
It works great with connecting the resx to their imported designer.cs files. However, if I can force VS to gen the files for me it would make things all the better.

Aug 23, 2011 at 7:30 PM

Take a look at my comment in this thread which explains how to do it. You should avoid hand modifying the csproj, and instead use the object model.

Aug 23, 2011 at 8:40 PM

While that thread is a great insight into using the DTE instead of exiting the XML, it still doesn't answer the need to run a custom tool.

After I set up my RESX files instead of connecting actual designer files from my nuget I would like to run the resx custom tool that I have applied with my script, be it XML edited or DTE edited.

How can I invoke the custom tool for the files that I need to have designer files for?

Aug 23, 2011 at 8:50 PM

Normally, the custom tool runs at the time you set the "CustomTool" property. Are you not seeing this?

You can also do it explicitly later by calling RunCustomTool.

Aug 23, 2011 at 8:52 PM

Correct I am not seeing this effect. I will try the link solution out and let you know what comes of it. Perhaps it is the fact that I am modifying the XML directly and the custom tool is not invoking because of this.

Aug 23, 2011 at 8:56 PM

Yes, you need to use the API as in the other thread to set the custom tool. It definitely will not run if you just hand edit the csproj file. If fact, that might cause VS to try to reload the project, which is pretty bad for the user.

Aug 23, 2011 at 9:13 PM

The reload is acceptable since it only happens once and save has been called on the project to insure any changes are placed into effect. I would expect that needing to save the project would be true regarding editing with the DTE as well.

Aug 23, 2011 at 9:24 PM

The save is needed. The reload is not if you use the API.

Aug 23, 2011 at 10:05 PM

Thanks for the input. I will let you know how everything turns out.