I am trying to publish my web app.
Here is a picture of my setting for my publishing profile:
As you can see, I have the "Precompile during publishing" option checked.
Here is the Configuration settings for "Precompile during publish".
When this is checked, and I try and publish my web app, I get an error on one of my pages. When I hover over the tab to see the file location, the location is at: C:\Users\akemp.WT\AppData\Local\Temp\WebSitePublish... This is not the location of my source code, and if I make the changes on my local page, the site in the above given path does not get updated.
When I unchecked the "Precompile during publishing" option, my website published without any hassle.
What is going on here?
Pre-compilation means all your source code (including aspx.cs files for web site projects, class files under app_code folder, resx files, the global.asax file, and even the aspx files - unless "Allow precompiled site to be updatable" is selected) are combined and compiled into assemblies.
global.asax will have it's own assembly, app_code will have it's own, resx files wll be compiled in assemblies per folder, while the rest of the source code (aspx, aspx.cs) will be compiled into a single (and huge, depending on number of pages) assembly, and all will be in the bin folder of the web application as dll files.
If you do not pre-compile, these resources (aspx files for instance) will be compiled with the first request targeting that page.
This will enable you to make aspx and aspx.cs deployments without recycling the application.
And because a web site canot be both pre-compiled and compiled-on-demand, VS cannot run your published web site where your source code is located. But if you don't pre-compile, your source code can directly be served (since the first request will compile the resources and the compiled assemblies will go under C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files (or another explicitly set temp path for shadow assemblies)
When I tried publishing with the "Precompile during publishing" option checked, I got an error on one of my code behind files.
When I made changes to my code behind file in visual studio, saved and rebuild my solution, and then tried to publish, the issue would still exist. When I double clicked on the error in the Error list, it opened my page's code behind file, except for the fact that it was the file located at "C:\Users\akemp.WT\AppData\Local\Temp\WebSitePublish...\RandomPage.aspx.cs", and not located at my source folder.
After I individually published that page on it's own (Right click on RandomPage.aspx.cs, and select Publish RandomPage.aspx.cs), I was able to publish my web app with the "Precompile during publishing" option checked.
Related
I have a site that I'm about to publish and I want to know how to set it so it would not deploy the code behind?
Essentially i'm trying to find the difference between an aspx file that calls the code behind .cs file and another that calls a dll that's in the BIN directory?
The below explanation from the Microsoft ASP.NET documentation discusses the difference between explicit and automatic compilation.
In order for the ASP.NET engine to service a request for this page,
the page's code portion (the WebPage.aspx.cs file) must first be
compiled. This compilation can happen explicitly or automatically.
With explicit compilation you need to copy up the assemblies in the
Bin folder, but you do not need to copy up the ASP.NET pages' code
portions (the WebPage.aspx.cs files).
With automatic compilation you need to copy up the code portion files
so that the code is present and can be compiled automatically when the
page is visited.
When you publish a web project (from Visual Studio), the source code from code behind (.aspx.cs files) will be converted to a binary dll file named as [YourWebProject].dll and will be copied under the "bin" folder.
We are working on a website project which contains around 1130 pages. After compilation, all the .aspx.cs files are converted into AppCode DLLs that has random names.
Whenever there are any changes in single .aspx.cs file[like a hotfix], we have to recompile and deploy the entire project on the application host.
We want to update only those files that have been changed and not the entire package.
One of a solution we are aware is that, converting Website to Web application; but we cannot implement that change at this stage of the project.
Is there any other way to find an efficient solution for this?
Yup. Talking in Visual Studio 2010:
While publishing the website, Select the option: 'Use Fixed naming and single page assemblies', Also select 'Allow this precompiled site to be updateable'.
After website is published. Go to the published folder. Open any aspx page (not the dll or .cs).. Note the dll name in page attribute under inherits attribute. Than using ftp or any other way to upload, copy or upload tht dll under bin to your website.
Also, you can create a doc or txt file to list all Dll names with respective paths to your file to easily know which dll to upload next time if there is any change.
Hope it helps.
In Brief:
In an ASP.net website with a code-behind, at what point are the *.cs files compiled?
Context:
A colleague who has since left, deployed a website with a .cs code-behind to a shared server. I have made a small change to a .cs file, which I should expect to reflect on one of the pages but it has not yet appeared. I have restarted the application pool, however I am loathe to reset IIS on the server as there are couple of other teams' apps which might be be in use on the same server.
This applies to Web Application projects as opposed to Web Site projects, which are CodeFile by default, and don't allow changing the build action...
In ASP.NET Web Applications you have two methods of deploying your pages; CodeFile and CodeBehind. By default pages will always use CodeBehind but you can change this.
CodeBehind
CodeBehind compiles your .cs file into the .dll file in your bin folder at compile/build time, and then you deploy that to your web server. There is no need to deploy the .cs file to your web server. If you do, it will just sit there being unused.
To configure a page with CodeBehind, ensure that:
The page directive in your .aspx file has CodeBehind="your.aspx.cs"
The properties of the .cs and .designer.cs files in solution explorer have a build-action of compile.
CodeFile
This causes ASP.NET to compile the .cs file on-the-fly on the server. This means that your .cs file needs to be deployed to the web server. It also means that your .cs file will not be compiled at compile/build time and therefore not built into your .dll in the bin folder.
Key advantage
With CodeFile, You can make changes to the .cs file and deploy just that file to see the changes on your production web server. No need to re-deploy. No need to recycle the app pool. This can be very useful in a lot of situations.
To configure a page with CodeFile, ensure that all of the following are met:
The page directive in your .aspx file has CodeFile="your.aspx.cs"
The properties of the .cs file in solution explorer have a build-action of content
The properties of the .designer.cs file in solution explorer have a build-action of none.
Notes
Intellisense doesn't like working when pages are set up with
CodeFile (you can change to CodeBehind whilst coding and then change back for deployment, though).
If you change from CodeBehind to CodeFile, then always do a
rebuild and re-deploy (and vice versa). This is because when the page was CodeBehind,
the .cs was compiled into the .dll in the bin folder, and will
remain there when you change to CodeFile. The CodeFile will be
compiled on-the-fly and you will get the same code/classes defined in
the .dll and in the on-the-fly compiled code, which will lead to
runtime errors.
For the setup I use, the .cs files are compiled when building the project. This means it is the .dlls in the bin that need to change, not the .cs files directly.
The .aspx files can change at any time, but I think you need to rebuild the project in order for the code behind to take effect.
I have replaced singular .dlls before without any problem (though it's not good practice).
Apparently what you have done should work.
Check if Cacheing has been implemented.
Otherwise publish the code and deploy the dll, instead of .cs file. I would recommend to test in staging server before you go live.
In my mvc3 web project I have an App_GlobalResources folder containing the resource file Permissions.resx.
I am able to access the values in this file when I run the site locally in visual studio using:
string value = (string)HttpContext.GetGlobalResourceObject(resourceClass, key);
However, once I deploy it to the production web server it is not able to access the values in this file. I checked and it is creating App_GlobalResources in the bin folder of the publish directory containing the file.
My first time using global resource files, is there any additional steps required to get this working once deployed to the webserver?
Thanks.
I'm pretty sure App_GlobalResources should not be created in the bin folder. Have you got Copy to output folder set? (You shouldn't need it).
In WebForms, in properties of the .resx files, we have Build Action set to Content and Custom Tool set to GlobalResourceProxyGenerator. This creates dlls for the resources in the bin folder.
However, I've not used App_GlobalResources in MVC (it makes things tricky to test outside of a web context), but there's some info here that might be useful:
http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx
I have a Visual Studio 2008 solution with an ASP.NET Web Application project. I want to change the default output folder, of said project, to $(SolutionDir)\WebApps\$(ProjectName)\bin. This I can do and when I build I get the expected assembly files in this folder. It doesn't copy the content files (aspx, etc.) to the parent folder but I have managed to fix this by hacking the project.csproj file with a custom build target.
The problem is I want to be able to debug this application using the ASP.NET Development Server, by pressing F5 in VS2008. Unfortunately the ASP.NET Dev server starts, has a "Physical Path", in the project directory rather than the parent of the output directory.
Is there any way to build my web application to a different output folder but still run the asp.net dev server to debug my site?
Thanks.
Short answer is yes, but it isn't pretty. The process I used is given below.
Unloaded the project in VS.
Manually edited the .csproj file to include a post build action that basically copies the content files (aspx, etc.) to the parent of the output folder.
For the debug options I set the project to launch an external executable. The Asp.Net Development server. Also manually set the url to launch.
What I learnt? I wouldn't do this, I'd just stick with the default and create an install/web deployment project instead.