MVC3 compiling views is slow - c#

When working on a c# MVC3 app in Visual Studio 2010, I have turned on view compilation by editing my project file and setting the wonderful flag
`<MvcBuildViews>false</MvcBuildViews>`
to true. I love it as it means I can compile my views and catch errors.
The only problem that I have now is that it's not really quick! (I have tried turning it off and then it's back up to full speed.)
It looks like it recompiles every view every time - I have about 50 views at the moment, so ideally it would only compile the pages that have changed since last time. Is this at all possible?

I don't think its possible to compile that way in the same project. You could attempt to pull out the views into a separate project, and set it up that way.
http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/

As far as I know, building the views is an all-or-nothing flag.
I recommend turning this option off for development environments, but turning it on for a continuous build system that's pointing at your main development branch. That way you can still get an email if you commit something that breaks a view, without adding a lot of time to each build during development.

Related

How to clean up blazor server project

I am new to blazor and I've chosen to learn blazorserver but whenever i create a project, it comes along shipped with a lot of stuff i don't need. I don't need the layout it offers. I want to build my own layout from scratch. I also want to get rid of bootstrap and replace it with tailwind. The problem is that there are a lot of files and directories that make me fear to break the app. Is there a kinda command that can generate a much cleaner project or some way of manually cleaning it app without breaking the app. I appreciate any help.
If you are afraid of breaking the app by deleting something then it's better to keep it. You already figured out that you can replace bootstrap library with tailwind and that you can replace the layout with your own. While developing on the project you will start understanding what is the purpose of each folder or file in the starter template. After you understand their purpose, you will be able to decide if you need them or not.
Also learning how to use version control (e.g. git), like #JHBonarius mentioned, is very good advice. So when you break something you can easily revert back to previous working version of code.

Wondering if we could generate code with T4 Template on a builded solution

I'm trying to figure out if we could generate code with a T4 Template file post-build.
In fact, I'm kinda new to c# and I needed to find a solution where I generate class from Xml file that could be edited by the user at anytime and the first solution that come to me is T4 Template.
Then I render those generated classes on a treeView and the according properties on a property grid.
Now, I think that it is only generate code at pre-build time, but I'm not sure about that since I don't really see a lot of stuff about that on the internet. I'm still pretty sure now that it's not possible.
So, a second problem comes to me : I finished my entire project like that, so if you all have an idea or another solution that could be nice, i'll really appreciate that.
The 'T4Executer' extension has an option to attach the execution of each T4 template to build events. Before, during and after build, or not run them at all.
Doesn't work for Visual Studio 2022 yet though.

Razor Generator adding empty comment lines in razor view

I have started using Visual Studio 2017 recently (moved from VS 2015). First thing i noticed my razore views are not compiling changes in generated files (generated cs files stay the same despite changes in cshtml files). When I tried to right click and select Run Custom Tool it showed me message which implies to install Razor Generator (which i did). Now after saving my razor view it's having lots of extra empty comment lines through out the view. Which is causing a bit of issues with final Html. Here is how that empty comments looks like:
Has anyone face this issue before? If yes please kind enough to share solution. Given the time I have, i will manually remove these extra comments as of now and will look at it later when i have more luxury of time to spend on it. Thanks in advance.

How to Apply Style Sheet to HTML Designer Only?

I am working on a Web application project and although I am an experienced Visual Studio developer almost all of that has been in WinForms, console apps, Services, etc. That is, I have very little experience with using VS to develop web pages (Web Forms, asp.net, etc.), however, I am learning how to apply my previous Web page knowledge to VS.
One thing that has been throwing me for a while is how to apply additional CSS files in development, that should not be used in production (because they are already there). Specifically, I am working on a set of pages (DNN module) that is being deployed into a larger website context.
This all works fine, except the VS Web Page Design Editor is nigh useless because it's WYSIWYG rendering is not even remotely close to what the page looks like on the site. I know why this is happening: the site (and DNN) have their own set of CSS files that are getting applied/added to the page.
I know that I could just add those same style sheets to my web page in development (using <link href=...> tags?), however, then the web page would be deployed referencing these CSS files twice (there's a bunch of them too).
So my question is, is there any easy solution to this? Is there some setting somewhere that I can just say "use these additional CSS files in development or in the Design Editor"? (I hHve tried to google this, etc. but I just find dozens/hundreds of articles about how to add or edit CSS in Visual Studio)
Unfortunately I think that may have mis-explained my need somewhat. The issue really is not a development vs production issues, but rather an IDE vs execution issue. When debugging the code or otherwise running it in development, it is still within the DNN test environment we have setup, so it does have the extra file even here.
This is really about the HTML designer, when i am using it it does not have these extra style sheets, so I cannot see what the work I am doing really looks like. Instead, i have to run it every time I want to see whether any change i make looks like it is supposed to. This gets extremely onerous, especially with how slow DNN is to compile and reload.
Hmm, do you have your web project setup to run on IIS instead of IIS Express?
Something I do is often just work in the project then Save and if needed build. Then browse to the Site on my machines IIS instance (right click file in solution explorer and select browse if using ASP.NET Web forms).
Once I have done that I can refresh my page. I also use #if Debug in my code to bypass user login and etc to make round tripping faster...

rebuild url with mvc bundle

On the website I'm building we are using the built in bundling and minification.
We render our scripts by using the #Scripts.Render
#Scripts.Render("~/bundles/scripts")
it generates a link like:
bundles/scripts?v=3-DUUAAegZl4yp1O4V0VL0GnJ0U6gT3De8yKb41lfGs1
Here I thought that the hash:
v=3-DUUAAegZl4yp1O4V0VL0GnJ0U6gT3De8yKb41lfGs1
would be smart and change if we made changes to the inlcuded scripts but it seems like that is not the case.
Now when we are trying to implement a custom cdn for out bundling it fails on updates since the hash never seems to change.
Does anyone know of a solution to change the hash when the script changes or if we are doing something wring?
Edit:
I noticed that there is a difference in behavior depending on what environment I'm using.
Local development it seems to be working but it doesn't work on the staging server.
Should there be a difference?
Edit2:
Seems to be working as it should on production servers as well. Will have to do more research on what the cause can be.
Edit3:
Seem that the one causing the problem was in the registry LogRewrittenUrlEnabled was set to false to allow url rewrites at the same time as using dynamic content compression (gzip) so will have to find another way to enable this
You're right, the cache-buster hash should change if you change the contents of a script. There's some useful information about how the cache for bundling works that may help you here ASP.NET MVC Bundling cache. (Detecting css files changes) (internal behaviour).
The problem was that on the server we had in the registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v LogRewrittenUrlEnabled set to false
And if you have that then the cache-buster hash is not refreshing when the content i bundle is changed.

Categories

Resources