简体   繁体   English

将 JavaScript 文件转换为 dll 文件

[英]Convert JavaScript file into dll file

I have a project with Visual Studio 2012 and i have Java Script files, and CSS files in this project.我有一个使用 Visual Studio 2012 的项目,我在这个项目中有 Java Script 文件和 CSS 文件。
I want to make all JavaScript files as DLLs and CSS files as DLLs just like my C# Code.我想像我的 C# 代码一样将所有 JavaScript 文件作为 DLL 和 CSS 文件作为 DLL。
Is that could be done ?, And with what tool ?可以做到吗?,用什么工具?
And if I'm working with bundles it will still can read from it?如果我正在使用捆绑包,它仍然可以从中读取吗?
Any help will be appreciated, Thanks.任何帮助将不胜感激,谢谢。

You can do this for JavaScript but not css using VisualStudio.您可以使用 VisualStudio 对JavaScript执行此操作,但不能对 css执行此操作。 You need to add your js files as Embedded resource and then reference them in your code.您需要将您的 js 文件添加为嵌入式资源,然后在您的代码中引用它们。

thisMSDN article goes into details but basically这篇MSDN 文章详细介绍了但基本上

  1. You add the file as an embedded resource thought VS您将文件添加为嵌入式资源认为 VS
  2. Use ScriptManager.RegisterStartupScript to register it使用ScriptManager.RegisterStartupScript进行注册
  3. Add a web resource attribute [assembly: System.Web.UI.WebResource("SampleControl.UpdatePanelAnimation.js", "application/x-javascript")]添加 web 资源属性[assembly: System.Web.UI.WebResource("SampleControl.UpdatePanelAnimation.js", "application/x-javascript")]

Personally I wouldn't recommend it .我个人不会推荐它 It makes the JavaScript horrible to debug, it prevents client side caching and it forces you to rebuild your site if you need to change the javaScript.它使 JavaScript 调试起来很糟糕,它阻止了客户端缓存,并且如果您需要更改 javaScript,它会强制您重建您的站点。 I'd simply add a <script> tag, like everyone's always done.我会简单地添加一个<script>标签,就像每个人都做的那样。

MSDN article on style sheet resources but basically it just references it using a link tag, so it's not the same as above.关于样式表资源的 MSDN 文章,但基本上它只是使用链接标记引用它,所以它与上面的不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM