Home > Software engineering >  How do I make the designer file update for project resources in an SDK-style project?
How do I make the designer file update for project resources in an SDK-style project?

Time:03-17

I converted my VB project into an SDK-style project, and everything was going swimmingly until I updated my My Project\Resources.resx file, and found that the designer file would not update. What changes to I need to make in order for the designer file to update with changes to the resx file?

CodePudding user response:

I assembled the answer to this partly from a code fragment in an issue raised with Microsoft here: https://developercommunity.visualstudio.com/t/vs-should-not-bloat-sdk-project-files-with-resx-de/574773

And partly from inspecting the contents of a non-SDK VB project with embedded resources.

The following fragment added to the project file will instruct Visual Studio to automatically update the designer file for Resources.resx:

  <ItemGroup>
    <Compile Update="My Project\Resources.Designer.vb">
      <AutoGen>true</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Update="My Project\Resources.resx">
      <Generator>VbMyResourcesResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.vb</LastGenOutput>
      <CustomToolNamespace>My.Resources</CustomToolNamespace>
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>

I had initially written a more general block (based on the material in the link):

<Compile Update="**\*. Designer.vb">
<DependentUpon>$([System.String]::Copy('%(FileName)'). Replace('. Designer', '.resx'))</DependentUpon>
<LastGenOutput>$([System.String]::Copy('%(FileName)')). Designer.vb</LastGenOutput>

(each replacing the equivalent line above)

But I found that Visual Studio wrote blocks for the specific resource file into the project file (as the link complains about), thus it seems more economical to just put the block for the specific resx/designer pair, especially if there's only one.

  • Related