title: "Run Custom Tool" for resx files in MVC2 project (from an external application/script)
body: <p>I am trying to get the localization for my MVC project working with our existing infrastructure for editing string resources. We store all our resource string in database tables and have a front end web UI to edit them with, and an export application which generated the .resx files. This all works great, but I am having a little difficulty with a new project using MVC2 and VS2010.</p>
  
  <p>I have asked <a href="https://stackoverflow.com/questions/3217173/do-i-need-the-resx-designer-cs-file">another question</a> on this, the answer to which almost got me there, but not quite.</p>
  
  <p>I have now changed the resources to be in a Resources folder (instead of App_GlobalResources), as recommended by a number of people. And have the following settings against my .resx files ...</p>
  
  <pre>
  Build Action             = Embedded Resource
  Copy to Output Directory = Do not copy
  Custom Tool              = PublicResXFileCodeGenerator
  Custom Tool Namespace    = Resources
  File Name                = MyApp.resx
  </pre>
  
  <p>I have changed my export application to run the <a href="http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx" rel="nofollow noreferrer">resgen.exe</a> tool with the following parameters ...</p>
  
  <pre class="lang-cs prettyprint-override"><code>string args = string.Format("/publicClass \"{0}\" /str:cs,Resources,{1},\"{2}\"", resourceFile, Path.GetFileNameWithoutExtension(resourceFile), csFilename);
  </code></pre>
  
  <p>... which generates an almost identical .designer.cs file as I get when I add the .resx file to my project initially. The only difference is the </p>
  
  <p>The generated .designer.cs file differs slightly from the file I get when I run the resgen.exe tool from within my export application.</p>
  
  <p>This is the code generated by VS2010 when I first add the .resx file to my Resources folder ...</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static global::System.Resources.ResourceManager ResourceManager {
      get {
          if (object.ReferenceEquals(resourceMan, null)) {
              global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Resources.MyApp", typeof(MyApp).Assembly);
              resourceMan = temp;
          }
          return resourceMan;
      }
  }
  </code></pre>
  
  <p>... the difference when I run the resgen.exe tool is that is prefixs <strong>MyCompany.MyApp</strong> to the namespace in the constructor to ResourceManager</p>
  
  <pre class="lang-cs prettyprint-override"><code>new global::System.Resources.ResourceManager("MyCompany.MyApp.Resources.MyApp", typeof(MyApp).Assembly);
  </code></pre>
  
  <p>Now, this to me seems to be a bug in the resgen.exe tool, because I've told it that the Namespace for my resources is <strong>Resources</strong>, not <strong>MyCompany.MyApp.Resources</strong>.</p>
  
  <p>So, is there a fix/work-around for this problem?</p>
  
  <p>The only thing I can think to do at the moment is to post-process the generated .designer.cs file with powershell and fix it!</p>