locked
Including Javascript Resources from another assembly RRS feed

  • Question

  • I have another Class library that has a number of javascript files that I use in an ASP project. I want to use some of them in a javascript windows store app. How can I do this?

    I thought may I could do this

    <script type="text/javascript" src="/ClassLibraryName/include.js"></script>

    however when adding the reference to the assembly VS2012 throws the "Confirm unsupported references" message. If I go ahead will this work?

    Will it work if I build it as Windows Runtime Component project? Or do I need to copy the javascript files across manually and update manually whenever they change?


    Tuesday, October 16, 2012 12:28 AM

Answers


  • Hi Chris,

    I think the scripts files you originally embeded in the ASP.NET specific class library cannot be directly used by Windows Store javascript application. Those script files used by ASP.NET are just some embeded resources in the .NET assembly with some certain attributes (which is used by ASP.NET runtime to load them). However, the Windows Store app runtime won't recognize those attributes. So if you want to use those scripts, the simple and straight approach is still extract those script resources out of the assembly and add them into the Windows Store js project as script files.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    • Marked as answer by Song Tian Monday, October 22, 2012 8:57 AM
    Wednesday, October 17, 2012 2:40 AM
    Moderator
  • JavaScript Windows Store app projects can only reference SDKs (e.g. like WinJS) or WinRT components.  However, I don't believe ASP projects will be able to reference teh WinRT assembly so that might not be a good approach.

    The simplest thing to do would be to simply have the files in a common source location and then use linked files in both projects so that you don't have to maintain the same file in multiple places.  To do this in the JS store project, right-click the project/folder node and select Add Existing Item.  Navigate to the file(s) you want to add and select them, and then click the down arrow on the Add button and choose the link option.  This will make it a part of your package (e.g. will be included in the final appx, runs in local context, etc.) without copying a separate version to your project's local folder, allowing you to maintain a single copy (you should be able to do the same Add as Link operation in the ASP project.

    Wednesday, October 17, 2012 6:25 PM

All replies


  • Hi Chris,

    I think the scripts files you originally embeded in the ASP.NET specific class library cannot be directly used by Windows Store javascript application. Those script files used by ASP.NET are just some embeded resources in the .NET assembly with some certain attributes (which is used by ASP.NET runtime to load them). However, the Windows Store app runtime won't recognize those attributes. So if you want to use those scripts, the simple and straight approach is still extract those script resources out of the assembly and add them into the Windows Store js project as script files.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    • Marked as answer by Song Tian Monday, October 22, 2012 8:57 AM
    Wednesday, October 17, 2012 2:40 AM
    Moderator
  • JavaScript Windows Store app projects can only reference SDKs (e.g. like WinJS) or WinRT components.  However, I don't believe ASP projects will be able to reference teh WinRT assembly so that might not be a good approach.

    The simplest thing to do would be to simply have the files in a common source location and then use linked files in both projects so that you don't have to maintain the same file in multiple places.  To do this in the JS store project, right-click the project/folder node and select Add Existing Item.  Navigate to the file(s) you want to add and select them, and then click the down arrow on the Add button and choose the link option.  This will make it a part of your package (e.g. will be included in the final appx, runs in local context, etc.) without copying a separate version to your project's local folder, allowing you to maintain a single copy (you should be able to do the same Add as Link operation in the ASP project.

    Wednesday, October 17, 2012 6:25 PM