How can I precompile assemblies? - c#

I'm new to ASP.NET, and making a small update to a site that already exists. I am confused about the differences I see on the production server vs. the source code I've been given, and would appreciate any explanation or advice. Normally I would just continue reading and researching until I understood fully, but in this case I've been asked to make a small update to something ahead of my understanding. All I need to do is change one element in a form.
On the production site, there are files like \contact\survey.aspx; no .cs files exist in the directory alongside them, and there's no CodeFile directive. Instead, there are a multitude of DLL files corresponding to these pages, like bin\App_Web_survey.aspx.fdf9difs9.dll.
When I was given the source code of the site to edit, I see something different. The bin folder is entirely lacking in these DLL files corresponding to pages; instead, each aspx file has an aspx.cs file sitting next to it in its folder, a code-behind. Fair enough, I think; the site can run in its interpreted mode, like this, or compiled to DLLs.
Problem is, for the life of me I cannot work out how to do that; I've read dozens of pages on the MSDN library and gotten nowhere.
I am using Visual Studio Express 2013 for Web, and I've opened the source code folder as a website. When I run 'build', it succeeds, but no DLLs are made, not even in the Debug folder. This MSDN page has instructions for compiling web application projects, but the options don't correspond to the available options for me, so I'm guessing that either web application and web site are distinguished or that Visual Studio 2013 (which I also tried using and had no luck with) is distinguished from VS for Web. I'm at a loss.
tldr: Can anyone quickly sum up for me the process of compiling an ASP.NET website in a way that results in multiple DLL files in its bin directory?

You might need to use aspnet_compiler:
aspnet_compiler -p sourceCodeRoot -v / targetRoot
See How to: Precompile ASP.NET Web Sites for Deployment (MSDN).

Related

How do you "Build" an exe that includes all the resource files like pics? Can exe be put on a web page?

I have students in high school who have created some programs using Visual Studio C#. They created some games and would like to now upload them to the web. I am pretty new to Visual Studio C#. I thought after a program was "built" that you could go into the bin/debug folder and get the exe file for the program and be able to play the game without having to have Visual Studio on the actual computer you are playing it on. It works with some of their games but some of them, there are graphical files that are missing in the exe file if all the other files aren't stored in the same place. How can I get a clean exe of their game? Can that exe be loaded up onto a web server so they can play it from there or at least download it from there?
Microsoft wrote a guide on how to do exactly this. It's on their MSDN website, which is sort of like the developer back-bone for a lot of Microsoft software and documentation.
Old guide: Adding and Editing Resources (Visual C#)
Newer guide: How to: Add or Remove Resources
The gist is that the program needs to know where the files are, relative to the location of the compiled binary (in this case, an .EXE); There's several different ways to do this, depending on your level of expertise. I would suggest that you take a look at the guides above to start that journey.
there's a few ways of doing this. (Also, make sure you're creating a 'release' build when you compile).
You can include resources in your game by creating a resources file. This is something I usually do only on winforms applications etc.
If you have on-disk files you need to distribute those on-disk files along side your game. You could do this by zipping up your game.exe and the /files/images.img folder (or what ever your resources content folder is named).
If you're feeling adventurous you could create a 'deployment project' which is a project that allows you to create an installer file. This is a bit more work however you will have fine grained control over what files go where etc.
Good luck!
EXE files generally aren't self contained for video games with many resources, just add resources in an external folder and make sure the paths to the resources in their games are not absolute but relative in the local directory.
So for example:
get rid of paths like C:/Users/Bob/Desktop/Game/Images/player.png and replace with /Images/Player.png.
Also, an EXE generally doesn't run client side on webpages, it is possible but difficult. Things such as Flash are made for this sort of issue. I'd say make the webpage a place where they can download their games. Github has a nice way to do free websites called gh-pages. OFC, you could host one yourself but that would require a lot of setup work.
Like Monza said, you can zip up the files for download. Or, you could create an installer if you wanted to be really ambitious.
I thought after a program was "built" that you could go into the bin/debug folder and get the exe file for the program and be able to play the game without having to have Visual Studio on the actual computer you are playing it on.
That is correct, given that the other machine has the necessary .NET framework version installed AND any other resources like .dll files and config files are also present. When the application is ready for release, you can set the Build options in the project properties to Release, and then when you build all the files needed for distribution will be in the bin\Release folder.
It works with some of their games but some of them, there are graphical files that are missing in the exe file if all the other files aren't stored in the same place.
This may depend on how the application was written. If resources like pictures are embedded in the assembly then those files will not be needed to run on another machine. If the application is using hard coded paths for the image resources in the source code, then the application will likely break if the necessary files aren't present when the .exe is executed.
Can that exe be loaded up onto a web server so they can play it from there or at least download it from there?
Yes - you could upload the .exe to a file server to make available for a download, but you would not be able to run it within a browser over the web. I would recommend zipping up the .exe and other files needed and hosting the .zip file on the web server for download; browsers may give a warning or block downloading an .exe .
Hope this explains it a little bit for you.

Can I compile a single aspx.cs file into a DLL?

I'm attempting to make a single small update to a website written in C#/ASP.NET.
All I'm trying to do is change the email address a form submits to, which is why I'm not seeking out a proper C#/ASP.NET developer.
I've done a little research, and it seems that the site itself is using dll files in the /bin folder to run the forms and things. The form is contact.aspx.f3293f9sd.dll, so I've edited the corresponding contact.aspx.cs file.
What do I do now?
Can I build this single CS file into a single DLL and upload it? I've scoured the menus and see no such option, and Google results seems to imply that you need to add entire projects and build entire projects at once.
Is that correct? What's the process here?
What you need to do is open the solution file. Solution files are files composed of projects. The contact.aspx.cs file is part of one of those projects. You need to make your change in the file, then recompile your solution. Then you can upload the DLL file it outputs to your production. Make sure you compile in Release mode.

Compile LESS, minify CSS and JS and output to build directory

So, I recently started with ASP MVC4 and on my journey I discovered several new technologies and frameworks, such as LESS, Bootrap etc. (because I haven't done any web application in years!) whose capabilities completely blew my mind. I worked my way through various tutorials and the only thing I learnt is: How bad they work together. I just can't get anything working and its extremely frustrating.
What I want to achieve:
Having bootraps less source along with other site specific less files in one directory, such as Content\style\less\*.less (also for JS files: Scripts\*.js)
Compile LESS files at build (pre-build)
Copy all files to custom build directory, e.g. bin\style\*.css
Minimize and optimize css and js files in output directory.
Bundle all together at runtime
What I fail at:
Copy ALL files to custom build directory. Visual Studio just compiles the code and copies it to bin\
Compile less files properly. I created a pre-build instruction with the dotless.compiler.exe, but it fails at simple tasks, such as copying to new directory or reverse directory compiling (when I say compile \Content\style\less\*.less it just compiles every file in this directory, not in directories below.
Optimization and minify: It seems that the Web.Optimization bundling instruction only work at runtime, not at build time!
I hope anyone can help me.
Technologies and frameworks I used: ASPX, MVC4, Razor, dotless, Bootstrap, Web.Optimization
Edit: Regards the output task: Am I expecting too much? Compiling an application and copy every necessary resource to a seperate \bin (build) directory is a common element in .NET application production lifecycle for ever. Why not for ASP sites, since they are called applications aswell.
After installing Web Essentials, Shift+Alt+Y is the default keybinding for triggering a recompile of all .less-files.

How do "Temporary ASP.NET Files" get created (and how to prevent duplicates)

I have an issue where a dll shown twice in the Modules debug window for my WCF service (hosted by an IIS Project).
They are both loaded from my "Temporary ASP.NET Files" folders.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d9bf3211\b2544e2b\assembly\dl3\4cfa5823\28f464b9_9a03cd01\InversionOfControl.DLL
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d9bf3211\b2544e2b\assembly\dl3\4cfa5823\2457a584_9803cd01\InversionOfControl.dll
The paths are almost exactly the same, but the folder name that holds the dll is different.
So here are my questions:
What is "Temporary ASP.NET Files" for?
Why not just reference the dll that is in my build folder.
How could I have gotten two?
How can I prevent it from happening again?
If I just delete them will this problem be "fixed"?
The ones in bold are the answers I am most interested in.
You can feel free to delete anything below Temporary ASP.NET Files. All of the contents will be generated again (albeit with an initial performance penalty).
Also note that it is easier to use explorer to do this if you kill IIS temporarily. (iisreset /stop, delete the files, iisreset /start).
All you need to know different approaches for compiling your code by asp.net.
Do pre compile your code in order to avoid compiling and storing compiled files in temporary folders.
Hope this article will give you better answer for your questions. http://www.asp.net/web-forms/tutorials/deployment/precompiling-your-website-vb
Deleting them has no negative impact to your system.
.Net will just keep creating them slowly but surely filling up the drive. On dev machines, there are a lot of them. On servers... well, you shouldn't be deploying code to the server that requires compilation anyway.
Regarding whether it will fix your problem... maybe. Go for it.

aspnet_compiler -fixednames does not work?

I am unable to get the -fixednames switch to create dlls for the cs code behind files. The files in the bin folder are compiled aspx pages, but the code behind files are all compiled into one large websitename.dll file.
Here is my command with switches.
aspnet_compiler -v / -p E:\Source\DotNet4\mysolution\website -f -d -fixednames E:\Source\DotNet4\CompiledWebSite
This produces many files in the bin folder.
website.dll and website.pdb (contains code behind)
myform1.aspx.643c7876.dll (compiled aspx layout ui)
I have tested this over and over to make sure I am not missing anything. The test is place a label on myform1.aspx, and in the codebehind populate the label with some text. Compile the website with the above switches and deploy the website.
Make a change to the myform1 codebehind and change the label text. Compile and only deploy the myform1.aspx.643c7876.dll to the website. Result: label is still the same. Now deploy the website.dll and pdb and the label changes.
Can anyone tell me how to get -fixednames to create sinle dlls for codebehind?
I think the difference really is in the Web Application vs. Web Site concept. I created two identical apps - one as a Web Application, and one as a Web Site, in Visual Studio. The page was default.aspx, and the class is "_Default". When I ran "aspnet_compiler -v / -p . -f -d -fixednames ..\CompiledSite" on the Web Application, there were 2 dlls in the new bin, one called WebApplication1.dll, and it contained the _Default class, and one called App_Web_default.aspx.cdcab7d2.dll, which contained the markup. When I compiled the WebSite with the exact same command line, it only created one DLL, with both the markup and the _Default class.
Don't ask me how it knew the difference between the two - the only thing I can think of is the fact that the csproj file exists for the Web Application.
From what I've read and the way I understood things, aspnet_compiler was designed for WebSite projects, not Web Application projects, which is why I assumed you were using a WebSite.
If you need your application designed to be single-paged DLLs, try building a new WebSite project, adding your .aspx and .aspx.cs files to that WebSite, and compiling with your aspnet_compiler command, and see what happens. You can start with just one or two pages for a sample.
You won't need to actually test and recompile etc. in order to determine if it worked - just look at the DLL files in Reflector, and see where your classes live - if they live in the same DLL as the markup, then it worked, otherwise, they must be in the centralized application DLL.
Hopefully that all made sense - good luck.

Categories