VS2013 not adding Javascript generated from Typescript to project automatically - visual-studio-2013

I'm using TypeScript for the first time. I'm using Visual Studio 2013 with update 4, Web Essentials with update 4, and have the latest version of TypeScript from Microsoft's website. However, following the tutorial doesn't work for me: when saving a TS file, it automatically compiles to JavaScript on the screen to the right of the code I typed, and a JS file is created in the folder. However, this file is not added to the project automatically. How can I set Visual Studio 2013 to automatically add generated JS files to the project?

How can I set Visual Studio 2013 to automatically add generated JS files to the project
Use a glob for your TypeScript folder i.e. modify your .csproj file to include:
<Content Include="client-src\**\*.*">
</Content>

Besides Basarat's answer which works, there's also another solution: not doing anything. TypeScript generates a JavaScript file, which automatically gets placed in the same folder as the TypeScript file. When in Visual Studio, right click the folder your TypeScript file is in, and select "open folder in file explorer". You should see that the folder holds both the TS file you made, and the JS file that got generated.
You do not need to add this JS file to your project folder inside Visual Studio: you can just reference it. If you have an MVC project with a Scripts folder that has a file called greeting.ts (the one you make in the TypeScript tutorial), the path would be "~/Scripts/greeting.ts". Instead, just use "~/Scripts/greeting.js" (ending with js instead of ts). Visual Studio is smart enough to figure it out from there. This works with bundles as well.

Related

Visual Studio 2022 Custom Project Template doesn't show after unzipping / zipping

I have created a new Project Template by exporting a project via Project -> Export Template. Opening Visual Studio now, I can see my template showing up.
I then went to
Documents\Visual Studio 2022\My Exported Templates
and moved the MyTemplate.zip to another folder. Went to
Documents\Visual Studio 2022\Templates\ProjectTemplates
and made sure that MyTemplate.zip is not in there as well.
Now when I open VS again, I can see that my template is not available anymore.
To counter check, I moved the zip back into Documents\Visual Studio 2022\Templates\ProjectTemplates , reopened VS and made sure that the template is visible again.
I then went ahead, extracted MyTemplate.zip and compressed it into a zip again (Right Click -> Compress to Zip). Now when I move that zip into Documents\Visual Studio 2022\Templates\ProjectTemplates and restart VS, the template does not show up.
Bottom line, I am unable to import any template that I have manually compressed into a zip archive, seems like something is happening to the zip during extract / compress. I have been testing this on Win 11 with the OOB zip tools as well as nanazip.
Did you try extracting your template project ZIP file?
I was struggling as well but as soon as I extracted my custom template project with the rest of the Default templates it started showing up.
VS template is looking for folders in the ..\Visual Studio 2022\Templates\ProjectTemplates\ not a zip file. If you want your template to show up, move its folder there.
In my case the problem was that I named the XML file .vstemplate. It needs to be something.vstemplate.

How Do I Compile Copied and Pasted Files in a Visual Studio Project Solution?

I just created a new project in Visual Studio 2019 and copied a bunch of files into the source/repos/project directory but they don't compile. I am guessing that is because these files were not created using Visual Studio.
Is there an easy way to make sure that the Project compiles all files in the directory even if they were created elsewhere? Right now all the files that I pasted in are treated like hidden files and the build option is a greyed out "None" instead of "Compile."
The files in question are all folders, PHP files, CSS, Javascript, etc.
See screenshot
enter image description here

TypeScript only compiles if previously compiled JavaScript file has been deleted

I am using Angular 2 in Visual Studio 2015, inside of an asp .net 4.5 project. When I build and run the project, JavaScript files are created correctly. However, if I make any changes to the TypeScript and recompile, the JavaScript isn't being overwritten. The only way I can get the TypeScript to recompile is by deleting the previous JS file.
I would first suggest opening Visual Studio as Administrator to see if it is a permissions issue, whereby VS2015 cannot overwrite your JS files.
Otherwise, right click on the project in your solution (not the solution itself) and select Properties.
You should have a tab called TypeScript Build as shown in the screenshot below. Ensure that you have Compile on Save checked.
"compileOnSave": true
must be added to tsconfig.json.

VS 2013 Community Add new Typescript file missing

Downloaded and Installed Typescript 1.4 from typescript page into VS 2013 Community Den Update 4.
Following install (no error messages), I tried to add a new typescript file. I expected to see such an option in the righ-click menu on "ADD new". Cannot find any reference to typescript files anywhere in any of my projects.
I can manually create a file and give it a ts extension in the "Scripts" directory of my project. However, there is no intellisense and no indication that a "shadow" js file has been created.
I'm at a loss as to how to get typescript working in VS 2013 Community Edition
I think I found the problem.
To use typescript in conjunction with an existing project in Visual Studio, I had to add a new project (using the typescript template) to the solution containing my existing project. Then, I could add new typescript files to the typescript project.
The generated javascript files in the TypeScript project could then be made available to the pages in the existing (co-)project by selecting the "Output to Folder" option on the Typescript project, specifying the scripts folder in the other project.

How can i load a template I have created in Visual Studio?

After creating a solution for a project, I exported it as a template. Now after exporting it automatically adds the template to my IDE and creates a ZIP file with all the project files and a .vstemplate extension file.
Now i am on another computer with visual studio and i wish to load this template and save it in the IDE, but i cannot find this option anywhere. The temporary solution i have is to open an empty web application and copy all the contents of the ZIP file not including the .vstemplate file. So my question is how can i load this template into my IDE?
When opening the vstemplate file in Visual Studio all i get is a text editor and XML data.
I am using Visual studio 2013 with Update 4.
Once you've exported your template, copy the entire ZIP file that was created to the folder C:\Users\[User Name]\Documents\Visual Studio 2013\Templates\ProjectTemplates. (You might want to use one of the provided subdirectories to keep your template organized.)
Restart Visual Studio, and then use the search bar in the New Project dialog to help you find the project template you just added.
For the record, it looks like using templates changes with VS2017. Your project template provider will have to publish via a new build mechanic, and it'll be a bit different than just dumping a .zip into a user folder:
Using Project/Item Templates:
https://learn.microsoft.com/en-us/visualstudio/extensibility/upgrading-custom-project-and-item-templates-for-visual-studio-2017
Create Project/Item Template:
https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-custom-project-and-item-templates

Resources