Set ASP.NET Bundling To Not Remove Third Party Copyrights - asp.net

I'm moving ASP.NET bundling into a site I have and I noticed that it is removing all comments from the code including copyright header comments (in CSS and JavaScript). This would be ok if it was my copyrights as I could just create my own IBundleTransform and add my copyright to the top, but it is not ideal to do this with third party copyrights.
Are there any good ways to keep these copyright headers (or maybe a flag that I haven't fround in the MSDN documentation)? Thanks!

Current Answer (Updated 1/2016)
The original answer (see below) is still valid; however, JavaScript has changed a lot since 2013. This rapid change is even compounded by the fact that ASP.NET 5 doesn't even have Bundling in it anymore.
My current solution is to use a JavaScript tool to do the bundling and minification for me. Things like Uglify have options to minify while keeping important header comments. You can combine this with a tool like Gulp, Grunt, etc to trigger this process on build, project loading, or even on demand. This can be accomplished with the Visual Studio window called "Task Runner Explorer", which is built into Visual Studio 2015 and is available as a Visual Studio 2013 extension.
Using a JavaScript tool for minification doesn't fix the issue with cache busting that Bundling solved. There are JavaScript tools to fix this (i.e. gulp-rev), but I don't like the way that they work with ASP.NET. One way of doing this while maintaining a high cache age for static content is to use some sort of hash or fingerprint in the URL. Microsoft employee Mads Kristensen wrote a post about how one might do this caching busting in ASP.NET on his personal blog.
In addition, HTTP/2 and if you are making a site forward facing you will not want/need to combine scripts in bundles like we used to.
Original Answer
As a follow up, the solution I used was to use Bundle instead of ScriptBundle or StyleBundle and just sticking all third party libraries (already minified anyways) into one bundle.
I was about to use #Robert Havey's excellent answer for Bundle Transformer when I realized I could get by without the minification and make a bundle with all third party JS or CSS.

Related

Single Page Application Project Templates for.NET 4.5 and Angular

Has there ever been a more confusing/difficult time to be a web developer using the Microsoft stack? That's not really my question... I know that the answer is a categorical no. :)
The single page app template that comes with VS 2013 is deplorable.
I've been working on building up a similar project template that uses Angular JS on the client, but I'm starting to spin my wheels a bit porting over the external (openId/oauth) login features.
I believe this is because of the lack of good, single-point-of-truth, and current documentation for Katana's auth/security bits and also because of how unreadable the client side code is in the S.P.A. template in visual studio 2013.
I know that I can get through it, but while I'm struggling with it, I'm wondering:
Are there any good community provided project templates or example code bases in existence that use .NET 4.5 (MVC5/Web Api 2), Angular JS, the new ASP.NET Identity stuff, and the Katana packages?
There's HotTowel.Angular, but it takes no stance on security. Besides, it's a Nuget package, which can't or shouldn't dictate as much as a proper project template can.
I agree with your observations. I have found the following setup that seems to meet your requirements and I think works very well (I don't have a template), I would suggest the following:
Create an empty WebApi2 project and adopt authentication/authorization depicted here
Use a regular index.html in the base directory as a launching point for your angular application. You can either maintain your client packages with nuget, npm, or bower.
Use whatever technique you like for organization of client code.
Personally, I would create 3 projects, One for client code, (mydomain.com) One for your api (api.mydomain.com) and one for your Model/Repository/Data Access layer.
update
Here is an open-source project that might be what you're looking for!

ASP.net Bundle.config VS BundleConfig.cs

I have created a new ASP.NET 4.5.1 web forms project.
I have used bundling & minification in MVC 4 previously.
Why is there a bundle.config file in the root - and a BundleConfig.cs file in App_Start - that both appear to list files to be bundled?
What is each for and why do they appear to do the same thing?
This question was asked here but not really answered (even though it is marked as such):
Bundling resources via bundle.config vs BundleConfig.cs in ASP.NET 4.5 WebForms
A lot of it comes down to whether you prefer working in code or in markup, but each does have some pros that are specific to that method.
For the bundle.config, there's really only a single benefit, but it is a big one. By using it, you can manage bundles without having to touch code at all. This means that you can make changes without recompiling, making quick deployments easier. Also, it means that your front-end developer, who is going to be most familiar with the files that should be bundled, can define the bundles without having to work with any back-end code.
However, there are quite a few limitations on what you can specify in the Bundle.config. For instance, you can't specify any custom transformations to be applied to individual items or bundles. The only bundle properties that you're able to set are the Path, CdnPath, and CdnFallbackExpression. You can't set the Orderer or EnableFileExtensionReplacements properties. You don't have a way to include a directory including all subdirectories (like you can with the IncludeDirectory method). Basically, there's a LOT of functionality that is only available through the back-end code. Granted, a lot of this you could set by using back-end code to retrieve a bundle that was defined in the bundle.config, and then manipulating. But if you're going to do that, you might as well create the bundle in the back-end, also.
My personal philosophy is to use Bundle.config unless I need to do something with the bundle that's not possible that way. However I'm sure some completely reasonable people would disagree with that.
As far as the default VS template for Web Forms projects having both, I'm guessing it's just to demonstrate that both options are available, since it's not doing anything in BundleConfig.cs that couldn't also be done in Bundle.config.

Where can I get the source code for MVC4

I would like to look into the way bundling is implemented. It seems like there is default bundling as my MVC project knows all about adding in javascripts that I don't have and never explicitly included.
Bundle is simply logical group of files that could be referenced by unique name and being loaded with one HTTP request. Two things that will help you use these new features, are RegisterTemplateBundles() and EnableDefaultBundles().
Bundling of scripts is a new feature in MVC 4, to learn more about it take a look at New in ASP.NET MVC4: Bundling and Minification and Yet Another Bundling Approach for MVC 4
The purpose of bundling and minification is to help increase the performance of your Websites by reducing the number and size of HTTP Requests to the server.
If you want code examples you can find walk-troughs and source examples in Visual Studio's Nuget package manager. There are many other sources, comment if you want me to add more.
I believe it's at: http://aspnetwebstack.codeplex.com/

UI-Performance for ASP.net

I know that Grails and Asp.net cannot be directly compared but still, does anyone know if there's something available for ASP.net that even remote resembles the functionality of the UI-Performance Plugin for Grails?
You have to do all this explicitly yourself. Very cool plugin though.
Anyway:
Move your own JS to the bottom of the page
Minify that stuff using an msbuild task The MSBuildCommunityTasks Project has a few MSBuild tasks that may do what you are looking for including Merge and JSCompress.
Use YSlow with Firebug to track your score agains the Yahoo UI guidelines.
Script Minification and Continuous Integration with MSBuild
Have a look at Aptimize - http://www.aptimize.com/ - costs money but does the same sort of thing

How do you centralize UI across multiple ASP.NET sites?

One of the projects I was in charge of as a JSP/Struts developer at my last employer was a themes tag library (present on every WebSphere server as a shared library) that let any Java web dev in the company pull in any of the standard themes like intranet, public, etc. with minimal effort. The themes included header, footer, navigation, and links to css & javascript, etc. They could even customize things a bit when we gave them the option, like choosing a selected tab.
This setup was ideal because we could make centralized change to any standard UI elements and they were automatically pulled in by all sites using themes without any effort by the site developer.
With the new job I started in December, I've switched to using ASP.NET. I'd like to propose something similar in spirit to the themes app here, since we're running a bunch of different sites that should have a unified look and feel.
What's the best way to accomplish this? I'd rather not have to recompile anything to update the theme to make this work.
Edit:
Although I was hoping for a better answer, the .NET gods apparently don't approve of what I was trying to accomplish. Here are the three options that were found:
Compile a Master Page into a DLL and put it into the GAC:
This works in simple cases, but as a hack it's too brittle. I couldn't get it to work correctly with our site.
Create a virtual directory to the Master Page in each web app: This actually does work, although it doesn't make for a very comfortable development environment. However, one of the things we are trying to move away from is having to create virtual directories inside each web application. No dice.
Create a bunch of custom controls, compile them into a DLL, and put it into the GAC: This is the answer I selected. It's the least centralized option and requires more work for the developer of each site, but it seems to be the only Microsoft-blessed way.
In conclusion, I'm pretty frustrated with .NET over this. In the grand scheme of things Master pages are just code, and I don't see any reason why they couldn't be easily centralized for use in multiple web applications. This seems to be a major loss compared to JSP/Java.
You can put some UI into the form of custom controls or server controls (if not in MVC) and then place them in the GAC thereby distributing them. All references to the controls in that assembly will be pulled from the latest version in the gac. You can also do things via the Machine.config which is controlled at the server level rather than the app level.

Resources