views:

1677

answers:

10

I'm comparing it Java where you can start your application server in debug mode, then attach your IDE to the server. And you can change your code "on the fly" without restarting the server. As long as your changes don't affect any method signatures or fields you can just hit recompile for a class and the application server (servlet container) will reload the class.

I suppose this is impossible in ASP.NET since all classes are packed into assemblies and you cannot unload/reload assemblies, can you ?

So when you have an .aspx page and an assembly deployed to GAC and your codebehind changes you have to redeploy the assembly and reset IIS. I'm talking about Sharepoint applications in particular and I'm not sure whether you have to do iisreset for private assemblies but I guess you have too.

So the best way to debug aspx pages with code behind I guess would be to get rid of the codebehind for the time of active debugging and move into the page, then when it is more or less working move it back to codebehind. (This would be applicable only for application pages in Sharepoint, site pages don't allow inline code )

How do you approach debugging of your ASP.NET applications to make it less time consuming?

A: 

And you can change your code "on the fly" without restarting the server

You can accomplish this with ASP.net if you make a Web Site project (as opposed to a Web Application Project). Using a Web Site project, you can post changes to code-behinds without having to refresh anything on the server, and the server does the compile work for you on all code changes. See here for more info on this.

This should also solve your difficulties with deploying the assembly to the GAC. As the server handles all compilations for Web Site projects, you wont have to redeploy any assemblies when changing files.

Yaakov Ellis
I think you left out the link for "here"? And will this work with SharePoint?
shapr
+4  A: 
Artem Tikhomirov
-1: You don't explain the security implications of this or the changes in behaviour when deploying to a SharePoint environment with a more restrictive trust level.
Alex Angas
Thanks a lot. Why don't you explain it properly?
Artem Tikhomirov
+3  A: 

If you are using the GAC, you can at least do iisapp.vbs /a "App Pool Name" /r instead of iisreset (it's quicker to recycle a single app pool than to restart IIS).

Matt Bishop
+3  A: 

From Matt Smiths blog on how to get F5 debugging with sharepoint. A very cool trick.

  1. Create a web application project in Visual Studio (File -> New -> Project -> ASP.Net Web Application, not File -> New -> Web Site).
  2. Move the .csproj and .csproj.user files, along with the Properties folder, into C:\inetpub\wwwroot\wss\virtualdirectories\, where is the name or number of the web application corresponding to the SharePoint site you'd like to debug on.
  3. Attach the project to an existing solution (e.g. STSDEV project).
  4. Set as startup project (right-click project name, "Set as Startup Project").
  5. Access project properties (right-click project name, "Properties") and click
  6. Under the "Servers" setting, click "Use IIS web server", then enter the URL to the SharePoint web application you want to debug on, e.g. http://mymachine:99.
Nat
+1  A: 

First, develop on a computer running SharePoint. Preferably, this means running Windows Server 2003 on Virtual PC or VMWare. This will let you deploy and debug SharePoint code directly, rather than having to copy files between servers and use the remote debugger.

Use a VS add-in to simplify the process of deployment and debugging. I've been using WSPBuilder but I think there are others out there. WSPBuilder has commands to deploy solutions, package them as WSPs, and attach your debugger to the local IIS process. It won't allow you to add/remove assemblies on the fly, but you can set breakpoints and run code through the Immediate window in VS.

Depending on how your production server is configured, it's usually a good idea to develop on a server with full/trust security settings, including disallowing code blocks in ASPX files. This makes debugging a little more difficult, but it reduces the number of nasty surprises you'll have when your code is finally deployed to production.

DylanW
A: 

Use an automated testing framework (NUnit) to write integration tests. This won't work for everything, but of course, it depends on what you're testing.

If you also have TestDriven.NET installed, you can run individual tests with the debugger. This has been helpful.

A: 

WSPBuilder Extensions has a "deploy to GAC" shortcut, unfortunately it never works for me. But it's a really quick way to code->compile->test.

If you're not using WSPBuilder Extensions, you can instead open a command prompt and run

gacutil /u yourassemblynamegoeshere gacutil /i yourdllgoeshere.dll

If you do this often, you can put it in a post-build event or in a batch file. Also, I'm unclear whether the gacutil /u (to remove the DLL first) is necessary.

A: 

Normally in our development environment, we make sure not to have to do IIS reset all the time. Normally we simply copy our files to the bin folders and they are automatically loaded.

If you do that, you will have to modify your web.config to allow "Full Trust" to all those assemblies. WSS (thus SharePoint) use a different trust profile and even the most permissible of the profile doesn't grant full trust to the DLLs inside the bin folder.

You have to use the following trust profile in your web.config to make it work:

<system.web>
        ...
        <trust level="Full" originUrl="" />
        ...
</system.web>

Now hoping that everything will work fine on your side!

Maxim
-1: You don't explain the security implications of this or the changes in behaviour when deploying to a SharePoint environment with a more restrictive trust level.
Alex Angas
A: 
Henry
A: 

makes the magic here! about security impocations, I think we shouldn't worry about it since we only recommend using that setting on development machines only!

Ahmed