Web essentials - Run on build events - web-essentials

I am working on a project using Web Essentials to bundle and minify script files.
It works perfectly well and Web Essentials run when I save changes the to script files. We are currently several developers on the project and we face a problem every time we get changes from our source control (TFS). Changes to the script files does not trigger Web Essentials to run, unless we manually edit and save a script file. Since we have a few projects, we currently have to do this for every project.
Is it possible to trigger Web Essentials to run on builds (build events)?
I noticed that the bundle files include an attribute called 'runOnBuild'. This is set to true, but does not seem to do the trick.
I am also open for suggestions on alternative approaches (trigger via TypeScript compiler, etc.)

In the source code of Web Essentials I found out that Web Essentials uses AjaxMin. It is possible to create a build task for AjaxMin according to this thread: AjaxMin Build Task to minify all js to separate folder

Related

Best Practice for separating Web App Publish to IIS using VS Build Definitions

I have done a fair amount of research for publishing and deploying web apps with VSTS and so far I have found the following:
1.Use .pubxml files and pass the DeployOnBuild = True to MSBuildArguments
2.Copy and publish Artifacts and create a separate release definition.
We are currently using the first method, but found that the build can be marked as successful but the publish fails (in our case it was a bad transform)
So we decided to look into separating the publish step and to create a release for our changes.
The issue I am running into is that the copy files and publish artifacts step only copies DLLs and our .js and .html/.css changes don't seem to make it to the UI. As a work around I added these params to the Copy Files method but it is taking a long time to publish. (There are no issues with the release definition)
**\*
!$tf\**
**\!$tf\**
**\!Debug\**
**\*!pdb
All the guides online for using the Publish Artifacts and creating a separate release definition seem to say the same thing, and only push Dlls from the bin folder to the IIS server.
Here is my build definition:
So my question is, why aren't UI changes being deployed to the website when the release completes if this isnt an issue anywhere else?
No, not really. We usually not only publish DLLs and our .js and .html/.css as build artifacts, but for the whole web app.
The Visual Studio Build task usually with the MSBuild Arguments as (if you use ASP.NET build template, it's the default setting):
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
In this way, the web app (published files) will be copyed to $(build.artifactstagingdirectory) directly. So you don’t need the Copy Files task.
If you need to deploy all files, you can use ** in Copy Files task.
Then when you deploy the app to IIS server in release definition, the whole web app in build artifacts will be downloaded.

Include Css Intellisense from one project in another

I have multiple web apps running on a server that all use a lot of the same css/image files. In order make everything more centralized i've taken all of the files out of the projects and wrote a small static file server in asp.net core with some gulp tasks to manage the css. The goal was to have it act like a cdn (with only one machine) and serve some other api functions, but to work locally without internet access.
I figured that if i included the visual studio project in the solutions for my other projects they would have access to the css/scss files for intellisense, which was not the case.
Is there some way that i can reference the files in visual studio so that i can get auto completion in the apps' view files?
I solved this problem by creating a symbolic link that included the assets in the desired project.

Adding grunt output directory to ASP.NET web service

I am creating a javascript webApp and i deploy it using GruntJS. this web app will be deployed in an ASP.NET MVC Web Service. I want to add the dist folder (and any files created by grunt inside the folder) programmatically inside the visual studio project, so when I build and deploy the web service I can navigate to this folder. Hope I was clear!
Yes you can. Grunt is completely independent of IDEs and texteditors and is a really helpful tool for all kinds of web development in any editor.
Grunt is described as “a node based javascript task runner with which you can automate tasks like minification, compilation, unit testing, linting and more”. You can use it for example when you do not like to be dependent on an asp.net web server doing minification and bundling for you, or you simply like to be able to use tools that are not (yet) supported by the asp.net/Visual Studio ecosystem.
Here is all you need: http://joeriks.com/2013/08/06/can-i-benefit-from-grunt-for-my-visual-studio-based-web-development/
Hope this helps!
Try to tweak WebDeploy settings in your MSBuild file (*.csproj?) so it would include files from the dist folder into your web application during publishing.
The following tutorial should be a good starting point how to do it:
http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/deploying-extra-files
Also check ASP.NET Solution Template on Visual Studio Gallery

Run equivalent to "Build Page" command for Visual Studio web site project from command line

As outlined in Tip/Trick: Optimizing ASP.NET 2.0 Web Project Build Performance with VS 2005, the "Build Page" command available within Visual Studio web site projects does the following:
the solution will compile all of the class library projects like before, then compile the /app_code directory and Global.asax file, and then instead of re-verifying all pages within the web-site it will only verify the current page you are working on, and any user controls that the page references.
Is there a way to access this functionality from msbuild and / or the command line?
I am setting up an automated build of a large Visual Studio web site project (based on Kentico CMS), which consists of:
a large number of CMS-related pages and user controls that we do not change
a small number of custom "web part" user controls that we are actively developing, all within a CMSWebParts/Custom directory within the web site
Pre-compiling the entire site using aspnet_compiler takes up to 10 minutes, which is too slow for a commit build. Ideally, I'd like to introduce a step that pre-compiles just our custom code. Note that we don't actually deploy the pre-compiled output (not recommended for Kentico sites), this step is intended only to validate the code in the .ascx files.
The best way I've found to reduce the pre-compile time for small changes to large web sites is to use the ASP.Net Compilation Tool (aspnet_compiler.exe) with in-place compilation.
Our build script runs the tool using the following command:
aspnet_compiler.exe -v / -p C:\path\to\MyWebSite
This command specifies the physical path to the web site but does not set the targetDir option, which results in the application being compiled in-place.
The benefit of in-place compilation is that aspnet_compiler will by default only compile files that have changed since the web site was last compiled (you can force it to recompile everything with the -c option). For example, when I run the above command against the web site for the first time, it takes about 10 mins to run. If I then change a single file and run it again, it only takes 30 seconds or so.
You may be curious as to how the compilation tool "knows" which files have changed. Compiling in-place doesn't modify the application being compiled, i.e., you won't end up with files like App_Web_xdqqvn5q.dll and default.aspx.cdcab7d2.compiled in the bin folder of your web application. The output is actually generated within the "Temporary ASP.NET Files" folder. When you specify a physical path (rather than an IIS metabase), a folder within your profile is used, e.g. C:\Users\your.name\AppData\Local\Temp\Temporary ASP.NET Files. Your web application source code is cross-referenced with data stored in Temporary ASP.NET Files to work out what has changed.
I think this might be of help for what you need to accomplish:
http://msdn.microsoft.com/en-us/library/dd293881.aspx
From what I read you can run the build from Visual Studio Command Prompt or from the windows command prompt.
Update:
I couldn't find anything on the internet relating to building only one page but using aspnet_compiler without -c parameter should speed up the compiling process since it will only recompile what has changed. If only thing that has changed since last build was the content of one .aspx page then running the compiler should act similar to Build Page.
-c
Specifies that the application to be compiled should be fully rebuilt.
Components that have already been compiled are compiled again. If this
option is omitted, the tool builds only those parts of the application
that have been modified since compilation was last performed.
aspnet_compiler usage is explained on this page:
http://msdn.microsoft.com/en-us/library/ms229863.aspx

Using the Microsoft Ajax Minifier with Web Setup project & Source Control

I've just started investigating the Microsoft Ajax Minifer 4.0 for use with a Visual Studio 2008 Web Application I work on. It's proven easy enough to hook it into the .csproj file so it produced .min.js files for all scripts, however I'm stumped as to how to integrate this with the Web Setup project & Source Control.
Essentially what I want to do is have the resultant .min.js files included in the Web Setup project without having them included in Source Control because:
Having to check them out prior to the build being executing is a pain (the minifier cannot modify them if they're not checked out).
As they're created as a "build artifact" it just seems wrong to have them stored under source control.
The only option I've managed to come across so far is to explicitly include the .min.js files as part of the Setup project by right clicking on the Web Setup project and choosing "Add > File", and then having the relevant folder hierarchy duplicated in "File System on Target Machine" so that I can force the file to the correct location. This is neither elegant or simple/robust as:
It requires me to manually add every minified js file to the Web Setup project by hand
Maintain a copy of the relevant directory structure in both the Web Application project and the Web Setup project
Remember to add any new js files minified versions to the Web Setup project
Is there a better way of doing this?
The solution I eventually opted for was to include the minifier DLL in my project and create a handler (.ashx) that I've replaced all references to .js files with, so:
<script src="MyJsFile.js" type="text/javascript"></script>
Is replaced with
<script src="Minifier.ashx?file=MyJsFile.js" type="text/javascript"></script>
I have a configuration setting in my web.config file that allows me to determine whether script files are minifed or not.
Using the Microsoft Ajax Minifier with Source Control
The Microsoft Ajax Minifier generates
the minified JavaScript and CSS files
as the output of the build process.
For this reason, we recommend that you
handle the minified files in exactly
the same way as you would handle the
assemblies generated by the build
process. In particular, we recommend
that you do not include the minified
files in your Visual Studio project
and that you do not check the minified
files into source control.
If you include the minified files in
your project, and you use source
control, then you will encounter
problems. When files are checked out
of source control, they are checked
out with their read-only attributes
set. If you attempt to do a build, the
Microsoft Ajax Minifier will generate
an error when it attempts to write to
a read-only file.
source : Microsoft
From my understanding, this means do not add the -min files to the project, that's it. When IIS will build the app, it will create the files automatically. I think you must have Microsoft Minifier 4.0 to be installed on the web server tho.

Resources