在预编译部署的网站中添加卫星程序集

发布于 2024-08-11 08:07:29 字数 743 浏览 2 评论 0原文

为了在 Visual Studio 2008 中使用 GetGlobalResourceObject(),我必须将 .resx 文件复制到 Visual Studio 的 App_GlobalResources 文件夹中。应用程序预编译后,资源文件将被编译成相应的附属程序集,并按区域性名称部署在 \bin\ 文件夹下。这一切都很好。

但是,在预编译应用程序后,我无法添加新的附属程序集。我所做的是:

  1. 创建了一个卫星程序集:

    resgen 资源.applicationresources.es-ES.resx 资源.applicationresources.es-ES.resources al /t:lib /culture:es-ES /embed:resources.applicationresources.es-ES.resources /out:App_GlobalResources.resources.dll

  2. 已创建文件夹 \bin\es-ES\并在那里部署 .dll 文件。

不幸的是,GetGlobalResourceObject() 无法识别新添加的附属程序集,它会回退到默认(英语)资源。资源文件似乎没有任何问题,因为如果我将相同的 .resx 文件复制到 App_GlobalResources 中,然后编译应用程序,一切都会正常工作。

我缺少什么?顺便说一句,我的项目类型是网站,而不是 Web 应用程序项目。

In order to make use of GetGlobalResourceObject() in Visual Studio 2008 I have to copy a .resx file into the folder App_GlobalResources of Visual Studio. After the application is precompiled, the resource files are being compiled into the corresponding satellite assemblies and deployed under the \bin\ folder by culture names. This all works fine.

However, I'm unable to add new satellite assemblies after the application has been precompiled. What I've done was:

  1. Created a satellite assembly:

    resgen resources.applicationresources.es-ES.resx resources.applicationresources.es-ES.resources
    al /t:lib /culture:es-ES /embed:resources.applicationresources.es-ES.resources /out:App_GlobalResources.resources.dll

  2. Created folder \bin\es-ES\ and deployed the .dll file there.

Unfortunately, the newly added satellite assembly is not being recognized by the GetGlobalResourceObject(), which falls back to the default (English) resource. There seems to be nothing wrong with the resource file because if I copy the same .resx file into App_GlobalResources and then compile the application, everything works just fine.

What am I missing? BTW my project type is website and not web application project.

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

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

发布评论

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

评论(2

尤怨 2024-08-18 08:07:29

(来自 @ksa 的评论)

可能出错的一件事是 resgen 生成的 DLL 中的命名空间路径不正确,您可以使用 ILDASM 或 Reflector 来比较工作 DLL 和生成的不工作 DLL 中的命名空间。然后,您可以更改 resgen 命令行以使用正确的命名空间进行生成。

(From Comment by @ksa)

One thing that can go wrong is an incorrect namespace path in the DLL produced by resgen, you can use ILDASM or Reflector to compare the namespaces in the working DLLs and the generated not working DLLS. You can then change your resgen command line to generate with the correct namespace.

各自安好 2024-08-18 08:07:29

尝试连接到 AppDomain.CurrentDomain 中的 AssemblyResolve 事件,看看它是否确实在查找程序集。如果它确实查找它,您所需要做的就是保留动态加载的程序集及其路径的列表。

关于 AssemblyResolve 的一点说明是,如果没有程序集,则返回 null。这是默认行为。

Try hooking up to the AssemblyResolve event in AppDomain.CurrentDomain and see if it's actualy looking for the assembly. If it does look for it, all you need to do is keep a list of dynamically loaded assemblies and their paths.

One note about AssemblyResolve, if you don't have the assembly, return null. That's the default behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文