如何链接资源文件?

时间:2015-08-20 20:01:31

标签: asp.net-mvc localization embedded-resource

我有一个我已经复制到另一个项目的strings.resx文件。它有一个关联的strings.designer.cs文件。问题是,一旦我将它们添加到VS.NET项目中,它们就是分开的。

在旧项目中,strings.designer.cs是strings.resx的子代。如果我双击strings.resx,它会自动生成一个strings1.designer.cs文件。

如何重新创建关联?

1 个答案:

答案 0 :(得分:1)

我可以重现你的问题。

如果查看.csproj文件,在新项目中导入资源后,您可以找到包含ItemGroup项的<Compile Include="string.Designer.cs" />部分,类似于以下内容

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

所以要解决您的问题,请执行以下操作

  1. 在VisualStudio中卸载项目。
  2. 右键单击已卸载的项目,然后从上下文菜单中选择“编辑{您的项目名称}”
  3. 找到包含<Compile Include="string.Designer.cs" />
  4. 的ItemGroup部分
  5. 替换
  6. <Compile Include="string.Designer.cs" />

    通过

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

    现在重新加载项目广告,您应该会在解决方案资源管理器上看到您的文件相关