我需要 resx Designer.cs 文件吗?

发布于 2024-09-09 01:23:37 字数 276 浏览 5 评论 0原文

我的公司使用一些数据库表、网页前端和“导出”应用程序的组合来处理网站中的字符串资源。

当我们使用 VS2008 时,导出应用程序工作得很好,但自从切换到 VS2010 后,资源现在在解决方案资源管理器中的“下面”有一个 Designer.cs 文件。

问题是“导出”应用程序仅生成 .resx 文件,而不生成底层的 Designer.cs 文件。

那么,有没有办法不拥有这些 Designer.cs 文件,或者有某种方法可以自动重新生成(或者甚至导出应用程序可以调用一些命令来重新生成它们)

My company uses a combination of some database tables, a web page front end and an "export" application to handle our string resources in our web sites.

The export application used to work just fine when we used VS2008, but since switching to VS2010 the resources now have a designer.cs file "beneath" them in the solution explorer.

The problem is that the "export" application only generates the .resx files and not the underlying designer.cs files.

So, is there a way to not have those designer.cs files, or alternatively some way to automatically re-generate (or even some command the export application could call to re-generate them)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

深空失忆 2024-09-16 01:23:37

我遇到了 VS 2010 无法重新生成 Designer.cs 文件的问题,并且在其他地方找不到解决方案。

不过,我能够重新生成它们,而无需进入命令行。

为了解决 Visual Studio 2010 中的问题,我执行了以下操作:

  1. 删除了 Designer.cs 文件
  2. 右键单击​​主 resx 文件
  3. 选择 运行自定义工具

这会重建 Designer.cs 文件。

希望将来可以帮助别人。

I had a problem where VS 2010 would not regenerate the Designer.cs files, and couldn't find the solution elsewhere.

I was able to regenerate them though, without going to the command line.

To fix the issue in Visual Studio 2010 I did the following:

  1. Deleted the Designer.cs file
  2. Right clicked on the main resx file
  3. Selected Run Custom Tool

That rebuilt the Designer.cs file.

Hope that might help someone else in the future..

想你只要分分秒秒 2024-09-16 01:23:37

从MSDN我们有:

将资源编译成程序集

当您构建应用程序时,Visual Studio 会调用
resgen.exe 工具来转换您的应用程序资源转化为
内部的
称为资源的类。这堂课是
包含在 Resources.Designer.cs 中
嵌套在下面的文件
解决方案中的Resources.resx文件
探险家。资源类
封装了您所有的项目
资源进入静态只读获取
属性作为提供的一种方式
运行时的强类型资源。
当您通过 Visual C# 构建时
IDE,所有封装的资源
数据,包括资源
嵌入到 .resx 文件中
和链接的文件,被编译
直接进入应用程序组件
(.exe 或 .dll 文件)。在其他方面
换句话说,Visual C# IDE 总是使用
/resource 编译器选项。如果你
从命令行构建,您可以
指定 /linkresource 编译器
使您能够部署的选项
资源在一个单独的文件中
主要应用程序组装。这是一个
高级场景,仅
在某些罕见情况下是必要的。

From MSDN we have:

Compiling Resources into Assemblies

When you build your application, Visual Studio invokes the
resgen.exe tool to convert your application resources into an
internal
class called Resources. This class is
contained in the Resources.Designer.cs
file which is nested under the
Resources.resx file in Solution
Explorer. The Resources class
encapsulates all your project
resources into static readonly get
properties as a way of providing
strongly-typed resources at run-time.
When you build through the Visual C#
IDE, all the encapsulated resource
data, including both the resources
that were embedded into the .resx file
and the linked files, is compiled
directly into the application assembly
(the .exe or .dll file). In other
words, the Visual C# IDE always uses
the /resource compiler option. If you
build from the command line, you can
specify the /linkresource compiler
option that will enable you to deploy
resources in a separate file from the
main application assembly. This is an
advanced scenario and is only
necessary in certain rare situations.

终难遇 2024-09-16 01:23:37

如果您希望在构建项目时从 *.resx 文件自动生成 *.designer.cs 文件,则以下方法对我们有用,也可能对您有用:

  1. 关闭您的解决方案
  2. 将项目文件打开为 XML 文件您想要自动生成设计器文件。请注意,您需要将其作为 XML 文件加载。您无法通过项目属性页编辑这些设置。
  3. 将目标添加到项目中,如下所示:
<Target Name="GenerateDesignerFiles">
   <Message Text="Deleting old Designer Files..."/>
   <Delete Files="@(EmbeddedResource->'%(RootDir)%(Directory)%(Filename).resources')"/>
   <Delete Files="@(EmbeddedResource->'%(RootDir)%(Directory)%(Filename).designer.cs')"/>
   <Message Text="Generating Designer Files..."/>
   <GenerateResource
      Sources="@(EmbeddedResource)"
      StronglyTypedLanguage="C#"
      StronglyTypedClassName="%(Filename)"
      StronglyTypedNamespace="@(EmbeddedResource->'%(CustomToolNamespace)')"
      StronglyTypedFileName="@(EmbeddedResource->'%(RootDir)%(Directory)%(Filename).designer.cs')"
      PublicClass="true"
      >
   </GenerateResource>
   <Message Text="Generating Designer Files complete."/>
</Target>
  1. 找到名为“BeforeBuild”的目标。该目标可以被注释掉(默认)。
  2. 按如下方式修改“BeforeBuild”目标:
<Target Name="BeforeBuild">
   <CallTarget Targets="GenerateDesignerFiles"/>
</Target>

此解决方案基于项目文件的 ItemGroup 中列为“EmbeddedResource”的所有资源文件,例如

<ItemGroup>
  <EmbeddedResource Include="Resources\Creditor\Display_Creditor.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>Display_Creditor.Designer.cs</LastGenOutput>
    <CustomToolNamespace>Acme.Web.Resources.Creditor</CustomToolNamespace>
  </EmbeddedResource>
  <EmbeddedResource Include="Resources\InboundEmail\Tooltip_InboundEmailDetails.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>Tooltip_InboundEmailDetails.Designer.cs</LastGenOutput>
    <CustomToolNamespace>Acme.Web.Resources.InboundEmail</CustomToolNamespace>
  </EmbeddedResource>
  <EmbeddedResource Include="Resources\Creditor\Tooltip_CreditorDetails.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>Tooltip_CreditorDetails.Designer.cs</LastGenOutput>
    <CustomToolNamespace>Acme.Web.Resources.Creditor</CustomToolNamespace>
  </EmbeddedResource>
</ItemGroup>

免责声明:这已使用 Visual Studio 2013 和 C# 项目进行了测试。它可能适用于其他项目和/或其他版本的 Visual Studio,也可能不适用于。

If you prefer to automatically generate the *.designer.cs files from *.resx files when building the project, the following approach worked for us and it might work for you as well:

  1. Close your solution
  2. Open as an XML file the project file in which you want to automatically generate the designer files. Note that you need to load it as an XML file. You can't edit these settings through the project property page.
  3. Add a target to the project as follows:
<Target Name="GenerateDesignerFiles">
   <Message Text="Deleting old Designer Files..."/>
   <Delete Files="@(EmbeddedResource->'%(RootDir)%(Directory)%(Filename).resources')"/>
   <Delete Files="@(EmbeddedResource->'%(RootDir)%(Directory)%(Filename).designer.cs')"/>
   <Message Text="Generating Designer Files..."/>
   <GenerateResource
      Sources="@(EmbeddedResource)"
      StronglyTypedLanguage="C#"
      StronglyTypedClassName="%(Filename)"
      StronglyTypedNamespace="@(EmbeddedResource->'%(CustomToolNamespace)')"
      StronglyTypedFileName="@(EmbeddedResource->'%(RootDir)%(Directory)%(Filename).designer.cs')"
      PublicClass="true"
      >
   </GenerateResource>
   <Message Text="Generating Designer Files complete."/>
</Target>
  1. Locate the target named "BeforeBuild". This target may be commented out (the default).
  2. Modify the "BeforeBuild" target as follows:
<Target Name="BeforeBuild">
   <CallTarget Targets="GenerateDesignerFiles"/>
</Target>

This solution is based on all resource files being listed as "EmbeddedResource" within an ItemGroup of the project file, e.g.

<ItemGroup>
  <EmbeddedResource Include="Resources\Creditor\Display_Creditor.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>Display_Creditor.Designer.cs</LastGenOutput>
    <CustomToolNamespace>Acme.Web.Resources.Creditor</CustomToolNamespace>
  </EmbeddedResource>
  <EmbeddedResource Include="Resources\InboundEmail\Tooltip_InboundEmailDetails.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>Tooltip_InboundEmailDetails.Designer.cs</LastGenOutput>
    <CustomToolNamespace>Acme.Web.Resources.InboundEmail</CustomToolNamespace>
  </EmbeddedResource>
  <EmbeddedResource Include="Resources\Creditor\Tooltip_CreditorDetails.resx">
    <Generator>PublicResXFileCodeGenerator</Generator>
    <LastGenOutput>Tooltip_CreditorDetails.Designer.cs</LastGenOutput>
    <CustomToolNamespace>Acme.Web.Resources.Creditor</CustomToolNamespace>
  </EmbeddedResource>
</ItemGroup>

Disclaimer: This has been tested with Visual Studio 2013 and C# projects. It may or may not work for other projects and/or other versions of Visual Studio.

ゃ人海孤独症 2024-09-16 01:23:37

试试这个:

  • 右键单击​​ resx 文件
  • 单击属性
  • 设置属性:
  • 复制到输出目录: 始终复制
  • 自定义工具: PublicResXFileCodeGenerator

保存并再次构建。
问题解决了。

Try this:

  • Right click on resx file
  • Click on properties
  • Set the properties:
  • Copy to output Directory : Copy always
  • Custom tool : PublicResXFileCodeGenerator

Save and build again.
Problem solved.

沧笙踏歌 2024-09-16 01:23:37

遵循这些步骤对我有用。

  • 删除您的 Designer.cs 文件。
  • 单击属性
  • 输出目录 - 始终复制。
  • 自定义工具:PublicResXFileCodeGenerator
  • 保存并构建。
  • 右键单击 resx,然后
  • 单击运行自定义工具。

Following these steps worked for me.

  • Delete your designer.cs file.
  • Click on properties
  • Out put directory - copy always.
  • Custom tool: PublicResXFileCodeGenerator
  • Save and build.
  • Right click on resx and
  • Click run custom tool.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文