4thSpace
4thSpace

Reputation: 44310

How to link resource files?

I have a strings.resx file that I've copied to another project. It has an associated strings.designer.cs file. The problem is that once I add them to the VS.NET project, they are separate.

In the older project, strings.designer.cs is a child of strings.resx. If I double click strings.resx, it auto generates a strings1.designer.cs file.

How do I recreate the association?

Upvotes: 1

Views: 729

Answers (1)

Juan M. Elosegui
Juan M. Elosegui

Reputation: 6981

I could reproduce your issue.

After importing the resource in the new project if you look at the .csproj file you could find an ItemGroup section containing the <Compile Include="string.Designer.cs" /> item, similar to the following

  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    ....
    <Compile Include="string.Designer.cs" />
  </ItemGroup>

So to solve your issue do the following

  1. While in VisualStudio unload the project.
  2. Right click on the unloaded project and select "edit {your project name}" from the context menu
  3. Find the ItemGroup section containing your <Compile Include="string.Designer.cs" />
  4. Replace
<Compile Include="string.Designer.cs" />

by

<Compile Include="string.Designer.cs">
  <DependentUpon>string.resx</DependentUpon>
  <DesignTime>True</DesignTime>
  <AutoGen>True</AutoGen>
</Compile>

Now reload the project ad you should see your files related on the solution explorer

Upvotes: 1

Related Questions