如何修复 ASP.NET 网站中的 EmbeddedRessources?

发布于 2024-07-13 22:04:00 字数 891 浏览 7 评论 0原文

我试图在 ASP.NET 的类中引用 js 文件,但收到此错误:

程序集“XXX”包含名称为“XXX”的 Web 资源,但不包含名称为“XXX”的嵌入

资源告诉我我一定有路径引用问题,但我不知道它是什么。

这是层次结构

<Root>
   <App_Code>
      <Application>
          <MyClass.cs NameSpace="None" />
      </Application>
   </App_Code>
   <JS>
      <MyJSFile.js NameSpace="MyControls" Name="MyJSFile">
   </JS>
</Root>

所以在 MyClass.cs 中我有:

[assembly: WebResource("MyControls.JS.MyJSFile.js", "text/javascript")]

[ClientScriptResource("MyControls.JS.MyJSFile", "MyControls.JS.MyJSFile.js")]
public class MyClass : ExtenderControlBase
{}

所以我想有些东西我没有通过引用得到:(RootNampeSpace).(Path).(FileName).(Extension)

我的项目是 ASP.NET WEB站点,因此我没有在嵌入式资源中设置构建操作的属性。

另外,在 App_Code 文件夹中,如果我将 JS 文件放入 App_Code 中,说明语言与 App_Code 中的其他文件不同,则会出现错误。

I am trying to reference a js file in a class in an ASP.NET and I receive this error:

Assembly 'XXX' contains a Web resource with name 'XXX' but does not contain an embedded resource with name 'XXX'

Searching the web tell me I must have a Path referencing problem, but I can't figure what is it.

Here is the hierarchy

<Root>
   <App_Code>
      <Application>
          <MyClass.cs NameSpace="None" />
      </Application>
   </App_Code>
   <JS>
      <MyJSFile.js NameSpace="MyControls" Name="MyJSFile">
   </JS>
</Root>

So in MyClass.cs I have :

[assembly: WebResource("MyControls.JS.MyJSFile.js", "text/javascript")]

[ClientScriptResource("MyControls.JS.MyJSFile", "MyControls.JS.MyJSFile.js")]
public class MyClass : ExtenderControlBase
{}

So I guess there is something I didn't get with the referencing : (RootNampeSpace).(Path).(FileName).(Extension)

My project is a ASP.NET WEB Site so I don't have properties for Build Action to set at Embedded Resources.

Also in the folder App_Code I get an error if I put my JS file saying that the language is not the same as other file in App_Code.

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

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

发布评论

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

评论(2

三五鸿雁 2024-07-20 22:04:01

我的项目是一个 ASP.NET 网站,所以我
没有构建操作的属性
设置为嵌入式资源。

我认为这是你的问题,你无法真正嵌入资源,因为没有构建步骤。 如果省略程序集属性会发生什么?

My project is a ASP.NET WEB Site so I
don't have properties for Build Action
to set at Embedded Resources.

I think that's your problem, that you can't really embed the resource, since there's no build step. What happens if you leave out the assembly attribute?

飘过的浮云 2024-07-20 22:04:00

你可能会认为这是可能的,但老实说我不知道​​如何做到。 我可能只是错过了一些非常简单的东西...

您总是有另一种选择,即创建一个单独的类库项目,将您的资源嵌入其中,并从您的网站项目中引用它。

You would think this is possible, but honestly I can't find how. I may be just missing something really simple...

You always have one other option, which is to create a separate Class Library project, embed your resources there, and reference it from your web site project.

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