Serve static files from different project - asp.net

I have an ASP.NET MVC project that serves static files form its root.
I see that these files are marked as Content and Do not copy.
Nevertheless, when I hit run in VS the static files are served from the root of the project.
I would really like to gather some static resources in a different project, and have them served as well.
I tried to create a class library and reference it from the main project, but files marked as Content in the class library is not deployed when I hit F5.
Is it possible to serve static files from a different project? If so, how?

The simplest way to accomplish this is to to add a Post Build Event to your ASP.NET MVC project
Add an xcopy command to "WebApplication1 Properties -> Build Events -> Post-build event command line"
More information: Copy file(s) from one project to another using post build event...VS2010
Unfortunately this won't handle deletes or renames very well.

Related

ASP.NET Core WebApi wwwroot folder marked as ignored

It's time to learn ASP.NET Core, so I create test project. When I learn project structure I found then folder for static files (wwwroot) marked as ignored.
StaticFiles package was added as well as UseStaticFiles method was called on Configure. Why this happend? How should I fix tis?
Once you will add static files inside the folder, it will no longer be ignored by your Source Control Manager.

Just publish modified controllers, models and some parts of a ASP.NET MVC project

If I change my views (.cshtml) or styles (.css) or scripts (.js) in my MVC projects then I can publish it easily by right click on it and select Publish FILE_NAME
If I changed some controllers files or BLL classes or infrastructure classes,
Which files should be published? which DLLs?
Of course added references must be published but what are another?
Should I publish all the DLL files in the bin folder or just some?
Is there an easy way to VS detect modified files and publish theme by a command or...?
Edit1
I use FTP method to direct publish and upload our site to the server.
My Publish Preview Step Snapshot:
What is the name of DLL files that contains the compiled information of controllers, BLL classes and...?
I just published the MVC5Bootstrap-3-1-1-Less.dll and it worked!
So if we uploaded a website and then want only publish the new modified controllers or classes of the MVC web application (here: MVC5) to the server, we should upload the following files:
MVC5Bootstrap-3-1-1-Less.dll after build
Added references to the bin folder after build
Here is a image of how publish DLLs of bin folder from Visual Studio:
The publish wizard on the project (right click on project > Publish...) should automatically determine which files have changed and need to be updated, and show you what files will be updated.
After clicking Start Preview:

Making a build that removes source CS files

How to make a build in VS 2010 within an ASP.NET MVC application that would remove all of the source code (CS and VB) files? When I build a website or web app I usually copy the contents of the entire solution to the hosting server. Mostly clients get the source but sometimes I do not want to expose the source to the hosting server thus only the Public (or Content) folder, views, masters and the built DLL should be copied.
Manual solutions are not applicable. What do you guys use?
Click Publish from the Build menu, then select File System and deploy into a folder. The contents of that folder should have all the stuff you want and nothing more.
You can add del commands to the post-build script. (Perhaps wrapped up in a batch file)
You can even write a C# program that deletes the files, then run that in the post-build script.

ASP.NET Web Deployment Projects: getting rid of .compiled files

I'm using a Web Deployment Project in Visual Studio 2008 in order to prepare my ASP.NET application (ASP.NET web application, not ASP.NET web site) for being copied to several servers. I have to copy the files on local staging servers, on different servers via FTP and sometimes I have to fetch them from customers' servers.
So, it would be nice to have all files for deployment in a compact form without the necessity of doing a lot of comparing between source and destination. Web deployment projects have this nice feature: compile all your aspx and ascx files into a single (additional) assembly.
I somehow found out how to get rid of aspx placeholder files on the server, now I'd like to know if there is a (maybe self-made) way to get rid of these .compiled files.
From Rick Strahl's blog:
The .Compiled file is a marker file
for each page and control in the Web
site and identifies the class used
inside of the assembly. These files
are not optional as they map the ASPX
pages to the appropriate precompiled
classes in the precompiled assemblies.
If you remove the .Compiled file, the
page that it maps will not be able to
execute and you get a nasty execution
error.
Anybody out there with a creative idea, maybe using a module/handler which intercepts the check against the .compiled files in the bin folder?
The .compile file comes from pre-compiling on deployment. So you basically have 3 options:
Keep the .compiled file
Don't pre-compile and deploy source code
Turn this in to a Web Application instead of a Web Site and compile as an assembly
I have run in to the same problem myself. I actually choose #1 in most cases when dealing with deployment of Web Sites, but on the rare occasion when I know I am going to have to maintain the site for an extended period of time, I take the time to upgrade it to a Web Application.
I don't like the .compiled files either, but nobody gets hurt if they're there. So why bother?
You might want to take a look at Virtual Path Providers (KB how to here) in ASP.NET.
Credit for this suggestion must go to Cheeso and his self answered question here:
Can I get “WAR file” type deployment with ASP.NET?
I don't know about the .compiled files, but you could set up your servers to update their files with subversion instead of manually copying the files when you compile.
So you would compile the files using the Web deployment project (not into a single assembly), put them in a repository you created for this purpose, and on each server, just do an svn update to fetch and compare the files automatically.
I know it's not what you asked for directly, but it may be a path to explore.
Add "Exclude Filter" to your deployment project:
In the Deployment Project.
Right Click on Content Files.
Click on "Exclude Filter".
Add "*.Compiled"
click OK.
and thats it.
I remember at the days when I cant do Web Application with VWD Express, I use nant script to compile the project into a single dll and deploy, that would work (so I dont need the full VS to do dll deployment too), so if you really don't want to mess your project to Web Application, maybe this is a path to check too.
You can get rid of the .compiled files by using the aspnet_merge tool with the -r option.
Removes the .compiled files for the main code assembly (code in the App_Code folder). Do not use this option if your application contains an explicit type reference to the main code assembly.
If you publish your code as updateable (in publish settings) these files are generated. Uncheck that value and republish. This is an old question I know, but no answers are clearly defined for this here.

Filter ASP.NET web application's files when deploying

I want to deploy my web application (asp.net mvc), and I need to remove all the codebehind files from my project.
Any scripts that you guys know of to do this?
I prefer using a script since I can tweak it if need be.
Just select the publish web site option on your project and it should take care of that (if you use vs).
Menu Build/Publish Website
In Visual Sudio, right click your project and select Publish... in the appearing dialog, select "Only files needed, to run this application".
The Publishing wizard will compile all codebehind files to your assembly and remove them for publishing.
I'd recommend using a web deployment project. This will compile your website and copy all of the files needed to for deployment into a new folder (without code-behind files, as they don't need to be deployed). You also get a little more control this way, as you can set up pre-build and post-build events.
For instance, I've set up a post-build event on the web deployment project to execute a batch file which copies some files into the Debug/Release folder and then zips it up, ready for FTP'ing to the production server.
First, codebehind files are not recommended for ASP.NET MVC. Codebehind is the controller for ASP.NET standard files - but in ASP.NET MVC you have far more powerful controllers.
Second, why do you need to remove codebehind files? IIS / MVC / Web.config should be taking care of ensuring that *.cs etc. files do not get served and result in a 404.

Resources