Visual Studio 2013 isn't verifying .js files.
I have a separate .js file under a Scripts folder, that is then referenced in my ASPX page.
The intellisense works when the script is within an html page or a .aspx page, but not in a .js file.
Is there something I'm missing?
In order to get intellisense to work with js files referenced on your web pag you need to add a _reference.js file. It really doesn't matter where you put the file, but generally it should be placed along with the rest of your js files. Perhaps in a SCRIPTS folder.
Here is a good article explaining it in further detail.
For More Info: (http://gurustop.net/blog/2012/03/03/javascript-js-intellisense-auto_complete-in-visual-studio-11-beta-the-web-_references-js-file)
Related
I have a bunch of Javascript files in a centralized project in my solution that I would like to share amongst other projects. However, when building and testing a project with such a linked file, it is 404 when I try to access it in testing my solution.
The script is linked to from the standard Scripts directory in my project - nothing unusual in it's placement. It doesn't get loaded in my view (#Scripts.Render("~/Scripts/Models/InteractionDetails.js")), though the script tag for it does appear in the source and all the other JS files get loaded including a test non-linked js file in the same subdirectory.
How might I get the dratted thing to be properly deployed to the server on build?
This is not a duplicate, as I am using the method outlined to include the files in my project from another project. The issue is that they are not being used when I build the project (eg, I cannot path to the JS files directly on the server, and they are not included in pages referencing them).
I have a little problem.
I am including the jquery.min.js file as a script in my HTML file, but I want to use the jquery functions in a seperate .js file. In a situation like this the IDEs like PhpStorm or Visual Studio 2013 won't recognize that the jquery.min.js has been included in the HTML file. My problem with this is that VS won't autocomplete the jQuery functions that I use, and sometimes PhpStorm will have a problem with this as well. Of course the code will work when I test it in a browser, but I would like to have some syntax highlighting and autocompletion as well.
How can I state it to the IDE that I've included the needed jQuery file in my HTML page so that it will start recognizing the syntax and help me with autocompletion?
Thanks!
In Visual Studio, you can define reference path of your jquery.min.js on top of your .JS file. Also you can just drag and drop the jquery source file to your seperate .JS file and Visual Studio will automatically generate the reference path for you.
/// <reference path="Libraries/jquery.min.js" />
//rest of your code starts
Just started using Web Essentials and love its support of .coffee files. Big problem however: In Visual Studio, if you add the following reference to the top of a .js file, Visual Studio will include intellisense for the items in the referenced file:
/// <reference path="../../js/knockout-3.1.js" />
So, while writing my code I can type something like ko. and intellisense shows me all the functions knockout has to offer.
However the above XML reference is not allowed in .coffee files and in fact keeps them from being compiled. I can put the following in a .coffee file:
# #reference ../../js/knockout-3.1.js
This will compile but I lose the intellisense in Visual Studio.
How can I "include" other .js files as a reference and trigger intellisense in a .coffee file?
This is not currently supported.
See this stack overflow question:
CoffeeScript Intellisense
Also see this suggestion from web essentials:
https://webessentials.uservoice.com/forums/140520-general/suggestions/3782958-coffeescript-intellisense
I use VS2015. The way i do it is update the "references.js" file (right click on that file and click update)
see screenshot
normally I would go
<script src="~/Scripts/Controls/SomeScript.js"></script>
and this finds SomeScript.js in the "Scripts/Controls" folder of the same project that the ASP.NET .cshtml page is in.
The time has come however to share the javascript file between two projects. I need to move it to a library project.
What would the value of the src attribute have to be to locate the javascript file in a completely different project in the same solution? Do I have to do something else? How is this problem usually solved?
I have tried "Copy to output directory" on the "SomeScript.js" properties page and this copies the script and its containing folder to the 'bin' directory. However chrome reports "Not allowed to load local resource" when trying to access .js files in the bin folder.
The folder which your scripts exist must be within the project tree, especially if you are planning on publishing the app to a remote server. Visual Studio provides an option to Add Existing Items as a link, which would allow you to symlink items stored outside your project tree into a folder within your project tree. Any changes to the original file will be reflected in your project; however if the file is deleted, the link will remain, broken.
You must also add the following to the end of the project .csproj file before the Project close tag.
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
</Target>
This edit to the .csproj file will cause visual studio to actually copy the linked file to the location of the link at the end of the build.
In this way, you can still reference ~/Scripts/Controls/SomeScript.js in your project.
use this reference to resolve your issue: Server.MapPath("."), Server.MapPath("~"), Server.MapPath(#"\"), Server.MapPath("/"). What is the difference?
seems that the best way would be to use / at the beginning - that is the root directory.. you can manage your way down from there
I have a project called WebResources where I have all the JS files that I intend to use in 2 other projects (all three projects sit in the same solution).
I just spent 2 hours playing around with the file paths and VS just doesn't see the JS file (unless I specify the full path with the drive letter).
Is there a trick to including javascript files relatively from other projects?
My file structure is something like:
Project1
Default.aspx
Project2
WebResourcesProject
/js
testToInclude.js
No matter how I try to include testToInclude.js inside Default.aspx, VS doesn't see it.
Any ideas?
To include relatively a file like as an image, css or js, they should be placed in the same server.
Let's say your server root is http://localhost:8080/ , and you map each project to separate folders such as http://localhost:8080/WebResourcesProject/ and http://localhost:8080/Project1/ then you could include the js like this (from the default.aspx file):
<script type="text/javascript" src="../WebResourcesProject/js/testToInclude.js" />
You can easily try that if you deploy your projects into your local IIS. If you're using the development webserver that visual studio give us, it seems to be not that easy. If there is not any real need of having the projects separately or referencing files relatively, I would consider either merging them or making absolute references.