2010-04-23

Silverlight And Strongly Typed Resource Classes, adjusting the tool to work for Visual Studio 2010

In my current project for involving a Silverlight application I encountered the resource problem as described by Guy Smith-Ferrier on his page Silverlight And Strongly Typed Resource Classes.
The tools work just fine with VS2008, but I had just installed VS2010 and was ready to start with the brand new Visual Studio.Unfortunately, after installing the setup files from ResourceProviderCodeGenerators.zip they did not work in VS2010. I still had VS2008 installed to verify it worked on VS2008, since the VS2010 version can be installed separately next to the VS2008 version.

Guy has been kind enough to answer my comment I left on his website and referred in general short guideline how to adjust the source code to make it work.

I used Visual Studio 2008 to open Guy's projects to adjust the code and compile the installer.Visual studio 2010 version will work also I think, although I cannot guarantee it at this moment.

First step is to download the sourcecode from Guy's website and download the first link :

"The Visual Studio 2008 (.NET Framework 3.5) source code for the book is available here."

Unzip it and go to the folder "...\VS2008\CustomResourceManagers\Resources.Tools" and open "Resources.Tools.sln" You will want to build this solution first, it has a helper class which is used in the ResourceCodeGeneratorsSetup so it needs a reference from the setup project.
After having built this ( by default the Debug settings with output to .\bin\Debug\ folder) you can open the solution
"...\VS2008\CustomResourceManagers\ResourceCodeGenerators\ResourceCodeGeneratorsSetup\
ResourceCodeGeneratorsSetup.sln"

This is the actual setup project and it contains the source code we want to change.

Now, in the Solution Explorer, open the ResourceCodeGeneratorsSetup folder and then view the code of ResourceCodeGeneratorsInstaller.cs

In the source code look for "private static string[] visualStudioVersions = new string[] { "8.0", "9.0" }; (Line 41 it was for me). At this point I thought : well, can't be that simple now, can it?
Let's just try : I added "10.0" to the string array :



After Building the project and solution I went to the "...\VS2008\CustomResourceManagers\ResourceCodeGenerators\ResourceCodeGeneratorsSetup\Debug" folder and there was a new setup and msi file :



After running the setup I got a message another version was already installed and I had to uninstall it in via the add/remove programs Control Panel (this is named different if u have other windows version, I used Windows Server 2003)

After having done that I tried the setup again and now it was succesfull, but I was eager to try it out in Visual Studio 2010. So I made a quick Silverlight application. I created a Resources map
and added a default Resource1.resx file:



Rightclicked on the resx file in the Solution Explorer to get the properties and changed the Custom Tool property value from "ResXFileCodeGenerator" to "PublicResourceCodeGenerator" (without the quotation marks).



After this I opened the Resource1.Designer.cs (it's under Resource1.resx and right click, View Code):



Notice the

public class Resource1 {
..


and the the constructor:

public Resource1() { }

If we had used the default Custom Tool "PublicResXFileCodeGenerator" which VS2010 uses this would have been all

internal class Resource1 {
..

and

internal Resource1() { }

thus preventing it from being accessed from outside its own assembly.

I also made a test1 with value test1 entry in the resource file to test whether the code would be generated now in VS2010, as it didn't b4 our code adjustment in the setup project.

It now works like it should :




I want to thank Guy Smith-Ferrier for his support and his available source code that we can use freely to make our developer's life a bit easier.

2 comments:

  1. I have performed the steps mentioned above and the resulting installer can be downloaded from here: http://www.pochet.net/blog/2010/06/07/code-generators-for-generating-strongly-typed-resource-classes-for-visual-studio-2010/

    Emiel

    ReplyDelete
  2. Hi Don,

    Apologies for putting you to this trouble. I have updated the binaries and the source code for Visual Studio 2010 and you can now use them directly from the site without modification (http://www.dotneti18n.com/downloads.aspx).

    Enjoy.

    Guy

    ReplyDelete