typescript for web forms - asp.net

Is typescript supported on web forms?
I have an existing asp.net 4.5 web forms project where typescript does not seem to be working.
I cannot create a new file, but even if I rename an existing to .ts it does not seem to be working. No build, no intellisense, nothing!

Found the answers to my problems:
I was trying to find "Typescript file" in Web folder of the "Add New Item" dialog, although it is in the "Visual C#" folder ..... Why?
Unless you have a .ts file created with "Add New Item" in your project, the option "TypeScriptCompile" on the "Build Action" of the file properties is not available and it raises an exception. After the first file is created, then you find this option and can manually set it to a .ts file.
The option "Typescript file" is not available in the "Add File" options unless you have a .ts file created with "Add New Item" in your project and you are in a "Scripts" folder (if you name differently the folder where you want to add this file, this option wont be available). Of course you can add a .ts file from "Add New Item".
You cannot easily create a ts file by your own, you must use "New Typescript file" from menu. That is because: A) The code page of the file must not be Unicode (I was trying to figure out that problem for many hours). if you try to compile a unicode .ts file with tsc, nothing happens!! After I saved the .ts file as Greek(Windows) - in my case-, everything worked fine! B) The .csproj properties that must be set for each file to work correctly are quite complex. (I was trying to create a .ts file starting from a .js file and renaming afterwards.... and then playing with .csproj)

I just created a new Web Application using web forms (empty project).
I found I have to add the Target to my project file...
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc" #(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
You need to right-click and select "Unload project", then right-click and select "Edit". This block can go right at the end, just before the </Project> tag.
I didn't have any problems adding a TypeScript file in Visual Studio 2012.

Related

CSS file is not being deployed from bundle in MVC site

Bundles are new to me but in my _layout.cshtml file I have the following:
#Styles.Render("~/Content/css")
And in the App_Start\BundleConfig.cs file I have the following:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/Portal.css"));
When I view the site on localhost by launching it from Visual Studio, all the styles are inserted, like so:
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>
<link href="/Content/Portal.css" rel="stylesheet"/>
However when I deploy to testing server the portal6.css file is not included in the markup, and in fact was not even copied into my Publish directory. I manually copied that CSS file to the Content folder but it seems like the bundle is not referencing it.
Does any one know what the issue is?
...in fact was not even copied into my Publish directory. I manually copied that CSS file to the Content folder...
Sounds like it's just a case of marking the Build Action of the project file as Content in project file properties - otherwise, it will not be "published" as you have noticed/stated.
To view the portal.css properties:
select the file
then F4 or ALT + ENTER
in Properties tab/window check if Build Action is set to Content (chances are that it's set to None having been "manually copied")
example view of some css file (font-awesome.css) that needs to be "published"
Note: Assumes the file is "included in Project" (not just in file system) - so it should be visible in your Project view in VS (without the "view all files" toggle enabled).
Hth...
Check #1
In Visual Studio, right-click the file, verify BUILD ACTION = CONTENT. CONTENT = Include to deployment package files. This is the most common issue is this is set to NONE.
Check #2
If the above is correctly set, the next thing that can happen is your build is not seeing this property when building the project independently of the solution. This is what has happened to me. For some reason, the build configuration does not update the new property set on a file that's may be added to the project outside of the GUI.
Visual Studio
1) Perform "Clean Solution" or Clean under "Build"
2) Now "Build" or perform "Publish" and the file will now be part of the deployment package folder.
BONUS NOTE: And lastly, also note if your web.config setting debug=false, the bundle will build the default file names "file.css". If debug=true, this instructs bundle to look for "file.min.css" version and will grab the minifying file version. So this can cause unexpected results as well if the CSS file contents are different or contain css classes that don't match the original css file.

Web Setup project not including some content files from ASP.NET MVC project

I am making a WEB SETUP for my ASP.NET application. Below is my folder structure for content folder.
I have added a WEB SETUP project and have included the 'Primary output from Web' and 'Content files from Web'.
But when i right click on the 'Content files from Web' and select the 'Output' option I see the following
only my .svg font is added, the rest 4 files (.eot, .ttf, .woff and .otf) are not added. Even when I run the installer and after the setup is complete I still do not see these 4 files in the Content/font-awesome/font folder.
What should I do to add these to the installer as well ?
Some font related files under your Content folder are probably not specified as "Content" files. You have to make Visual Studio understand that they are Content files. Content files are eventually copied to the compiled output directory when you execute your setup.exe file.
Just select your intended file(s) (using Ctrl-click if there are multiple files), right click choose Properties and from the Properties window, in front of "Build Action" choose "Content" option.
Now when you will Build and run your Setup.exe file, these files would be copied to the output directory.

ASP.NET MVC 4 IncludeDirectory from a another referenced project

I'm facing out a strange problem while using ASP.NET MVC 4.
I have 2 "Web Site" projects:
The first named "MyWebSite"
The second named "MyWebSite.Support"
I need to include the scripts under MyWebSite into MyWebSite.Support, so i thought to create a bundle in MyWebSite.Support and to reference that directory (MyWebSite/Scripts) inside that bundle by using "IncludeDirectory"
The problem is that i didn't found a way to correctly do that. It simply doesn't work because the starting path for the IncludeDirectory should be "~", which is the project virtual root path.
PS: If you have another solutions they are welcome!.
I don't even know if it's a good solution (i usually am not a everything_related_microsoft developer)
You could add the scripts as a link to the other project. This will assure you that they are copied when you deploy and you can use them in bundles. To do that, right-click on your scripts folder and select "Add existing item". In the dialog box select the files you want to add. Instead of clicking "Add Item", click on the little arrow next to it and select "Add as a link".
This will not actually copy the files, but include them as a linked file.
This has several advantages:
Files are shared between projects at Design time
You only need to share the files you want, not everything
You don't need any IIS configuration
You can easily edit the same file from each project (without copying it)

"Place code in separate file" in Visual Studio 2008 with ASP.NET

I'm reading a book that recommends clicking a check box that says "Place code in separate file" when adding a new Web Form to an existing ASP.NET project. The book is using Visual Studio 2005 and there is a check box for "Place code in separate file" when you open the "Add New Item" dialog.
I am using Visual Studio 2008 and I do not see the "Place code in separate file" checkbox when I try to add a new item. Is there something I need to do to enable this? Was this functionality no longer possible/important in VS 2008?
I believe in 2008 it is the default behaviour.
If you add an apsx file it will add the aspx.cs without any interaction from yourself.
This option depends on the type of project you are building:
If you are building a Web Site (File | New > Web Site, contains an /App_Code folder, the code is not compiled into a .dll in the /bin folder) then you will have the option (ticked by default in VS2008/2010) to "Place code in separate file", and also "Select master page".
If you are building a Web Application (File | New > Project, doesn't have an /App_Code folder, compiles all .cs/.vb files into one .dll in the /bin folder) then you don't have the option to not create a separate code file, and when you add a new item it's either a "Web Form" or a "Web Form using Master Page".
VS 2008 adds a code behind file by default.

ASP.NET Setup Project - how to include static files not in VS?

I am working on an ASP.NET MVC web application, and am working on the Web Setup portion. We are using SVN for version control. One of the issues is that the we are currently having is that the web designers modify and add a lot of html, css and js files that end up in the Content folders, but they don't add them to the VS project, so the new files don't get included in the installer.
One option is that we have to try to teach them to always go into VS and manually add the files, but we're on a large project and it's getting down to crunch time, so trying to get people to learn something new in a technology that they don't know will result in too many mistakes, so I'd like to work around that if possible.
Is there some way to get the setup project just to include files from a folder on the file system, instead of a project's designated content files?
Thanks!
I think I've figured it out:
Make sure that the installer project includes the Content Files for the web app. Then go into the web app's csproj file with a text editor and find the ItemGroup where the static Content files are listed. Then add an entry with a wildcard in it and the installer will package them in.
<ItemGroup>
<Content Include="Content\test.html" />
<Content Include="Content\*.html" />
<Content Include="Content\*.gif" />
<Content Include="Content\*.css" />
<Content Include="Content\*.jpg" />
<Content Include="Content\*\*.js" />
Right click on the folder in the File System view of the Web Setup project, and select Add, File...
It doesn't look like you can add an entire folder this way though, so you would have to add every file individually to the Setup program.
EDIT:
Aren't all files from your project folder included in a WebSite project in Visual Studio? Then it's just a case of having your WebSite project and Web Setup project in the same solution, then right-click on the Web Application Folder in the Web Setup project, select Add, Project Output... and then select the WebSite Project in the drop down and Content Files from the list box and click OK.
Unfortunately I don't think there is an out of the box way to do this, as projects maintains references to the files individually.
You could achieve what you need via a custom macro, or asking your other team to edit the .csproj XML file (perhaps simpler or riskier, depending on their background).

Resources