When server knows when to compile project ? If I change aspx file it detects changes and compile it on request ? What about changes in cs file ? Thanks for any help
Basically, it depends on your project type.
Web Site projects are compiled on the fly and any code modification in the site folder will trigger recompilation on execution.
Web Application projects need to be manually compiled (you'll see a [your project assembly name].dll in the bin folder).
Also, check http://msdn.microsoft.com/en-us/library/dd547590.aspx for more information about the difference between the 2 project types (and how they are compiled).
Using VS 2010 you may create ASP.NET Web Application or ASP.NET MVC Application using .NET 2.0 - 4.0 of your choice.
The next details are applied for both ASP.NET Web Application and ASP.NET MVC Application:
aspx files most of the times contains only static HTML code and after you change it you don't need to recompile the whole project because server pickup your updated aspx file strait away. With cs files is different story, because in that case when you did any changes in cs file you need to compile it to produce new updated dll files which would contain your latest changes.
So if you did any changes in your cs files and did not recompile the project, your changes won't be available until you recompile the project.
Also using VS 2010 you may create ASP.NET Web Site application. In that case you don't need to recompile your project if you changing cs file. Your source code will compiled automatically by ASP.NET on the server after first request.
More about Summary of Differences between ASP.NET Web application projects and ASP.NET Web site projects you may find here: http://msdn.microsoft.com/en-us/library/dd547590.aspx
With all the project types that exist in Visual Studio 2010 you have to recompile your code every time you make any changes in your .cs files.
In VS 2005 and 2008 there was a project type named "Web site", with this project type you did not have to recompile if you made changes in a code behind file.
For more information check out the differences between CodeFile and CodeBehind.
/Viktor
Related
I have to fix a legacy web service project created in C# and asp.net. It is not possible to open the project in visual studio as source safe errors and other missing libraries cause too many compile errors. I am not that familiar with web applications in .NET.
Is it possible to update a single aspx.cs file in the website directory which has a connection string hard coded that needs to be updated. If so, how is this eventually compiled and updated in IIS?
After you've deployed to IIS, you cannot update the .cs file in ASP.net application as they are already compiled into .dll files in the bin folder. The files you can update are with extensions like .aspx .ascx and .config etc. You should modify the .cs file, compile and publish the dll into the bin folder.
I have an ASP.Net Core MVC simple project. When I start it without debugging (Ctrl + F5) and change any .cs File (Controller, for example), save it, and update the page in browser nothing happens. But it should automatically recompile and show changes, that was said in the book that I read.
Why can this happen?
I use Visual Studio 2019, .Net core 2.1.
If I manually close the page, and press start without debugging again it recompile and show changes in browser.
If I change .cshtml files (View) it takes effect as soon as I update the browser Page. So it is problem only with C# classes.
UPD dotnet watch works just fine for that purpose, but author of the book (A.Freeman, Pro ASP.Net core MVC 2 7th edition, chapter 6) did not use it:
Visual Studio supports detecting changes as soon as an HTTP request is received from the browser and recompiling classes automatically. To
see how this works, select Start Without Debugging. Once the browser
displays the application data, make the changes to the Home
controller. Save the changes to the controller class file and reload
the browser window without stopping or restarting the application in
Visual Studio. The HTTP request from the browser will trigger the
compilation process, and the application will be restarted using the
modified controller class
Why does this not work for me?
The book was written for Visual Studio 2017. It works as the book describes in VS 2017.
However, according to this, the auto-rebuild feature has not yet been added to Visual Studio 2019.
Original answer: (which applies when that feature is not available):
The difference is that .cs files are compiled into your project's DLL at compile time. For any new code to take effect, the DLL needs to be updated, which will only happen if you specifically tell it to recompile. This is why, when you deploy your project, you copy over the .dll file and not the .cs files.
However, views (.cshtml files) stay as plain text files and are compiled when you use them. If you edit a .cshtml, it's recompiled the next time the view is used. This is why, when you deploy your project, you do need to copy the .cshtml files.
Visual Studio does have a feature to let you modify .cs files while debugging and have it take effect immediately, but it doesn't support ASP.NET projects. It's called Edit and Continue.
However, you can setup dotnet watch to detect file changes and restart your application. There are instructions on how to do that here: Develop ASP.NET Core apps using a file watcher
I was just handed a C# web service project and first time doing C# and ASP.NET. The web service and .cs, asmx, and asmx.cs files are located in wwwroot dir of the IIS server. I am writing a PHP SOAP client that calls those asmx files via SOAP. I would like to change some of the hard coded settings in those asmx.cs and .cs files. I have tried the aspnet_compiler and Visual Studio would not load the project. Is there any way to update the code/logic in those files without Visual Studio or recompiling. This project was compiled before. When using VS 2010 - it tries to open the project, converts it and nothing happens. If I have to us VS - any clues why it is not loading those files? It opens them if I open the .cs files individually but then I can't rebuild the project.
Any help/hints would be appreciated.
Thanks
It seems that your project file (.csproj) is interrupted. Refer to other correct project file and fix it manually.
ASP.NET website will auto compile cs and run when asmx first requested. Compiled code is put at bin folder, while cs code is put at app_code folder. Make sure asmx code behide puts to cs file in app_code.
Sorry but it turned out be a Windows profile issue. VS could not load those project files due to my profile being full. Hope it helps someone else in the future :)
I have a solution, Asp.Net web application and inside the solution I have two projects. One contains VB code that handles the UI. forms etc. and the other one C# that basically uses Linq-to-Entity to handle my data. When I run the project from my local computer it works good. Now, to publish, I notice only when the UI Project is selected, the publish option is enabled. Why is that? If I publish this, would the other project not be published? Another question, I have XML files created in app_data folder, when I publish it, will I be able to access it?
Publishing only applies to web projects. If you've included a reference to the other project in your web project, it will be compiled and the DLL will be published along with your web project. Your XML files should be published along with your web project, if they aren't check their properties and make sure they are set to be published with the project (build action set to Content and Copy Always or Copy if newer is selected).
You have two projects inside your solution. One is web project and the next will be a Class Library project. All the codes related to Entity framework, LINQ queries, Database transactions, etc should be in the class library project. while building the class library it will automatically generate the DLL files. then you need only add a reference to the web project file. Then you will get all the classes, methods etc from the class library. there is no need for publishing the class library project. Because you have add the dll reference to your webproject. all the code file inside your App_Code folder shuold be converted to dll while publishing the web project. so dont worry about the files inside the App_code folder data.
Thank you
You dont need to publish reference projects individually or even the whole solution. It works simply by referencing the dll of your other project.
Both projects need to be compiled if not already
If your UI project has reference to dll from data layer project it will be published with your UI project.
You can publish it locally in another folder and test using iis express or your local iis and then publish it online with database. Update connection string and it should work if setup correct.
I've recently started to explore Daniel Mohl "F# C# ASP.NET MVC3" template.
Can anyone share on how this type of project should be deployed to IIS7??
Thanks.
You deploy it pretty much the same way you'd deploy a "normal" ASP.NET MVC3 website, but there is one extra step: you need to make sure your deployed website will have access to FSharp.Core.dll.
If you have admin access to your server, you can simply install the F# redistributable; if not, you'll need to make sure FSharp.Core.dll is included when you publish or create a deployment package. The way I handled this in our website (written in MVC3 with C# + F#) was to manually add a reference to FSharp.Core to the website project, then right-clicked the reference, clicked properties, then set "Copy Local" to true. If you use any assemblies from the F# Powerpack, you'll need to do the same for them.
If I'm correct, the template consists of a C# Web Application that references F# Libraries (DLL) project which contains some of the functionality (namely, controllers and the model).
From the deployment point of view, this is just a normal C# Web Application with some referenced DLLs (created in F#) that will be copied to the bin directory, so the standard deployment procedure should for Web Applications should work just fine. I didn't try it myself now, but try:
Publish application to some folder (right click on C# web project in the solution explorer)
Copy that directory to your web server
Follow the usual IIS configuration steps (see for example here)