How to enable compilation on the fly in Visual Studio - asp.net

I have an ASP.NET Core 2.2 application. I run it using Ctrl+F5. But if I change C# code, I don't see changes after refreshing the website in the browser. How can I compile on the fly?

This happens automatically when running out of process. More likely than not, you're working on an ASP.NET Core 2.2 app, where the default process model has now been changed to in process. When running in this model, you must explicitly rebuild. You can edit your project properties to switch back to out of process if you like.

Related

Why all .NET Core applications are console applications?

I have a very basic question about why all .NET Core applications are console applications. I did some google search but don't find any appropriate answer.
It's an interesting question, and I got here because I had the same thought: Why do I seem to always see a console on asp.net core apps? Are they all now console apps?
But it's a mirage. While you are seeing a console window, it's only because the code is using the console for output. The code that starts the app governs where the output is going to. For example, instead, the output could be ported to the Windows Event Log, which is what happens when the site is published to IIS.
If you create a default .netcore web app, and you look in the output directory, you will see two files:
YourProject.exe
YourProject.dll
If you double click the exe, it will start the website. You will see the console window appear and the app will start listening on port 5000.
But now rename YourProject.dll and try to run the exe. It will fail because the exe is just the startup code. Your website is actually in the .dll.
The point is that the console window you see when you start an web app is coming from the exe, not the dll. So the console window has nothing to do with your web app, it's just a convenient way to start up the app in a dev environment. You can also start it from the command line with dotnet YourProject.dll and it will run exactly the same as if you started it from YourProject.exe
If you read #HansPassant's comment, he says it exactly correctly, my answer is just an expansion of it.
.NET Core provides more than console applications out of the box, it has supported both WPF and WinForms since version 3.x. In the below documentation links from Microsoft you can see .NET 5.0 (which is .NET Core) is listed. If you're using Visual Studio you can chose between ".NET" (which is .NET Core and what it will be referred to going forward) and ".NET Framework" (which won't have any versions past 4.8). It should be noted, WPF and WinForms although on .NET Core are only supported on Windows.
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/?view=netdesktop-5.0
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/?view=netdesktop-5.0

Visual studio 2010 dialog halts automated build

I am working on a project with a build that is automated using NAnt. The automated build includes NAnt tasks to clean the machine, including deleting and re-creating the virtual directory, clearing out VSWebCache, etc. Once the machine is reset, it attempts to compile the site with this:
<exec program="${visualstudio.install.dir}\devenv.com" commandline="SolutionFile.sln" failonerror="true"/>
The problem is that the automated build locks up at this point.
If I open the .sln file interactively, the first thing that happens is Visual Studio prompts me with a dialog box. I suspect this dialog box is "opening" (invisibly) when I run the NAnt script and I can't click on it to proceed.
The dialog message is:
Microsoft Visual Studio
The web (URL) is currently configured for use with ASP.NET 1.1. Web project (name) is targeting ASP.NET 4.0; if not configured some features may make incorrect assumptions, and pages designed with the tool may not render correctly.
Would you like the site to be configured for use with ASP.NET 4.0?
I do in fact have 3 different versions of .NET on my machine-- I work on multiple projects. I can't configure the site ahead of time because the build script will blow away my configuration anyway. I guess what I need is either an automated way to accept the dialog (as if I clicked the YES button) or a NAnt task that will automatically set up the vdir to be an ASP.NET 4.0 application.
I do have free reign to modify the build script as I see fit, but I cannot simply remove the portion that resets the machine-- our build box is shared with other projects and we have to reset everything to a known good state before running our compile.
Use MSBUILD directly, don't use devenv. It's the full IDE, and all you need is to build.

Is There a Visual Studio 2005 ASP.NET debug and release build

Is there a "debug" and "release" build in VS 2005? If so, how do I switch between the two?
Saif:
Are you working on an ASP.NET web site project?
If so, Visual Studio delegates the build step to the ASP.NET runtime, and the ASP.NET runtime picks up debug versus release in the web.config .
I have a post on the topic that will help: Debug and Release Builds in ASP.NET 2.0
Note that a couple things have changed since that time. Namely, MSFT released two add-ins for VS 2005 - one to add real web application projects that have debug and release settings (for the code-behind and loose c# files), and they also released web deployment projects, which can use the asp.net command line compiler. Web App projects became a part of VS2005 in SP1, too.
Use the Configuration Manager. Right-click on your solution in the Solution Explorer, select "Configuration Manager...", and change the active solution configuration.
You can change your project's behavior when in debug or release mode. Bring up your project properties pane, select the appropriate configuration from the dropdowns at top, and change the settings as appropriate. Notice that some changes are made by default for you. For instance, release builds by default are set to optimize code, and debug builds are not.
In the ASP.NET web.config file there is a debug="true" attribute. The first time you run the web application Visual Studio will ask you if you want to turn on debugging, selecting yes will cause Visual Studio to edit the config file for you.
Just remember to make sure you change that back to false for your release builds. For more info click here.
The quick way is to right click on the toolbars and turn on the standard toobar. Then you can quickly change between build targets by choosing the one you want from the solutions configuration drop down.
If you want to change what those configurations do, then follow what Michael Petrotta said in his answer.

ASP.NET 2.0 application won't compile when adding a Microsoft Report to the solution

I have a ASP.NET 2.0 web application. To that solution I add a Report (Reporting Services).
I make no further changes to that report. When I try build the application the build fails with the following error originating from that report file:
A namespace does not directly contain members such as fields or
methods
The problem was Visual Studio. I've restarted the IDE and could compile the application without problems.

How to properly set up Application Pools for IIS6

I am really stuck with this Parser Error Message telling me "Could not load the assembly 'App_Web_amlohswi'. Make sure that it is compiled before accessing the page." I have been looking around for a few hours checking different posts here and googling information. I have found out that I need to set up a new Application Pool that runs .NET 2.x.
(On a side note, my app is being developed in .NET 3.5, is there a way to set it up to use 3.5 instead of 2.x?)
Can someone provide me with a good explaination on how to set this up properly and (optionally) why is it necessary?
I am more used to developing in PHP so I am used to edit src >> upload >> success!
Thanks!
ASP.NET 3.5 sites run in 2.0 app pools as long as that version of .NET is installed on the system.
You may have to set up web.config properly. Visual Studio should do this for you when you create a new project.
You should also make sure you don't combine 1.1 and 2.0 applications in the same app pool. Try putting it in a separate app pool and see that helps.
Since #Trull provided you with a link to the "how", I'll chime in with the why.
.Net 3.5 just builds on the base .Net 2.0 libraries so you don't need to set it up for 3.5. .Net 2.0 and .Net 1.1/1.0 share some of the same name spaces and classes and therefore you need to choose which set of libraries you want to use with your application. Since your application uses the libraries from .Net 2.0, you need your app pool set up to load these libraries for your application rather than the .Net 1.1 libraries. You will also need .Net 3.5 installed on the web server, even though you only configure the app to use the (base) .Net 2.0 libraries.
This would basically be the equivalent of different versions of PHP. You would expect an application written using PHP 5 (and taking advantage of constructs in PHP 5) to work with a PHP4 interpreter. You'd need to upgrade to the newest interpreter (or at least choose the newer one if both are installed) before your app would work. It's the same with .Net -- you need to choose the right version, the version that your code expects to reference before it will work.
Here is how you use 3.5 in IIS. All hail Hansleman!

Resources