Dennis van der Stelt

The most votes generally drown out the best votes

Community

News

  • Addicted to Refactor! Pro

Email Notifications

I read...

I Use...

Tags

Recent Posts

Archives

Twikini, the mobile twitter client

Twikini_Theme_HTCBlack[1] I’ve owned a Windows Mobile for some time, currently the HTC Tytn which sure is up for replacement. But I’m really waiting for the HTC Touch Pro 2 or the HTC Hero or something. With internet on it, it’s great to have the ability to check your email, search the internet when you’re waiting or be able to find customer addresses or something. And of course the ability to tweet about what you’re doing.

For that I’ve been using Twikini for some time, and I love its features. It’s really fast, as it’s written in Native C++ for maximum performance. The menu is also laid out very well and you have the ability to create a tweet and add a twitpic with your camera while you’re at it. This ability makes it wonderful to tweet about special events with family or friends and when you see something exciting happening on the road.

Trinket Software, creator of Twikini also has some other great applications. When you buy Twikini for only $ 4.95 you’ll get an additional application for free. Or, if you blog about Twikini like I just did, you get it for free! :)

More info and downloads right here : http://www.trinketsoftware.com/Twikini

Is Azure ready for production usage?

Last week at the SDN Event in Houten, I presented a session on Windows Azure and how you can develop applications on it. How it differs from developing for servers that run on premises. After the presentation, the question was asked if developing for Azure was a wise idea, as some stuff did not seem production ready.

After thinking a bit more about this, I believe the person based his question on the fact that I talked about two subjects

  • Creating Azure Storage tables in the cloud and not being able to detect whether they’re there already.
    Read this article from Steve Marx for more info, although since the article it changed a bit. Blog coming up on that.
  • Deleting all entries in a table (truncate table) isn’t (directly) possible via the API.
    You’ll have to read every entry and delete each of them manually.

I’ve talked about this and perhaps because of this (or me) people got the impression Azure is not production ready. Maybe these issues will be solved, maybe not. These are all API related issues though and have nothing directly to due with Azure being production ready.

From what I’m observing, the Azure team is working really hard to get Azure working and perhaps spends less time on tooling and API. I’m very sure these will come in the near future, but we can already develop for Azure and it’s less important than getting a complex technology like Azure ready for release. And that’s what I am sure of, that the team is making sure Azure will work.

Is Windows Azure production ready?
The short and simple answer is probably no, because Windows Azure has not been officially released yet. But in my opinion it’s definitely worth checking out, because –as I said during the presentation- Microsoft is investing heavily on it. Invest in Azure now and reap the benefits of it sooner or later. It is expected that cloud computing will be as common in usage, as plugging in an electric device and instantly getting power is common right now.

SDN Event June 2009

DSC_0166 Yesterday was a great day as the SDN Event took place in Houten. The location was really great and the food never has been better. The poll on the website shows others agree with me. Thanks to those who attended my sessions. Sorry to those who wanted to know more about SQL Data Services, but know that all I demoed yesterday in Silverlight 3 and .NET Ria Services should be (almost) immediately be transportable to Azure and SQL Data Services in the near future. I included scripts to generate the database for the Silverlight demo.

I have uploaded the slides and demos to the media section on BloggingAbout.NET.

  • Windows Azure (slides and demo)
    Met Windows Azure kunnen we applicaties hosten in de cloud. Maar wat betekent dat voor onze applicaties? En wat is het verschil tussen de web-role en worker-role? En hoe communiceren deze? Hoe slaan ze data op? Wat betekent dit voor development en deployment? Deze vragen zullen beantwoord worden in een sessie met weinig slides maar veel code om een WCF service te bouwen waarmee we informatie over mobiele flitsers beschikbaar maken.
  • SQL Data Services and Silverlight 3 (slides and demo)
    Silverlight 3 heeft nieuwe mogelijkheden om eenvoudiger met een backend systeem te communiceren en gegevens uit een database te bewerken. Met SQL Data Services kun je een database 'in the cloud' plaatsen waarna je geen zorgen meer hebt over infrastructuur. Maar wat zijn de mogelijkheden en wat is er anders dan bij een lokale database? Nog interessanter wordt het als we deze twee technologieën gaan combineren. In deze sessie zal getoond worden hoe met Silverlight een LOB applicatie is te realiseren met het door Windows Azure gehoste SQL Data Services als storage model.

If you have questions about Azure, Azure Storage, .NET Services, Silverlight or anything else, don’t hesitate to contact me. And know that we give courses about all these subjects as well at Class-A! :-)

Attempted to read or write protected memory in a .NET application

Now this got me puzzled today for some time. I started up Visual Studio 2008 and opened a solution I had been working on for some time. But when trying to debug the application, it threw an error on Unity and the SerivceLocator trying to get an instance of a class. Not an interface, a class. It had no constructor nor dependency properties or anything weird, but I used Unity because it was supposed to in the future.

Anyway, I got an error from Unity and some inner exception said

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Now that was super weird of course. Weirder even was that all tests, also using Unity,  still all succeeded. So I replaced the line of code to instantiate the class by hand and it worked. A few lines further LINQ was used and the same error occurred. So I tried everything from running other applications and opening other VS2008 solutions, doing memory tests, etc, etc. Everything worked fine, but just this one project I was supposed to work on.

I Googled and even Blinged for some time, without finding anything relevant. Until I stumbled upon this thread in the Microsoft forums. There they did not find the error just weird, but wierd even.

Anyway, the solution was to enable JIT optimization. In other words, in Visual Studio 2008 choose “Tools” and then “Options”. Select “Debugging” and “General” and find the line that says “Suppress JIT optimization on module load”. This kind of makes sure that the debugger and the JIT compiled code aren’t running out of sync because the JIT compiler is such a super duper optimizer of your code. This did the trick.

Of course my code is so much optimized it never runs out of sync, but it still didn’t feel good. So I was trying to reproduce the error and turned “Supress JIT optimization” on again. To my even bigger surprise, the error did not return and my application is working just fine again. This even more ensured me turning it on or off on my own code, does not make a difference… ;-)

Typemock Isolator 5.3.1 can fake DateTime.Now

I just downloaded and installed Isolator 5.3.1 which has the ability to fake DateTime.Now, probably one of those functions in .NET you’ve always wanted to isolate correctly in tests. And now you can. For quick reference, check the Typemock Insider blog.

This can however be a breaking change in your unit tests. For example, we had the following test to verify of a DateTime was put into a property.

Isolate.Verify.WasCalledWithAnyArguments(() => someObject.ProcessDate = DateTime.Now);

With version 5.3.1 the test failed with the following error message.

TypeMock Verification: Method MyNameSpace.SomeClass.ProcessDate was called with mismatching arguments.

I fixed this by setting the following behavior on DateTime.Now.

// Arrange
var testDate = new DateTime(2000, 1, 1);
Isolate.WhenCalled(() => DateTime.Now).WillReturn(testDate);

// Act
// Some code here

// Assert
Isolate.Verify.WasCalledWithAnyArguments(() => someObject.ProcessDate = testDate);
DevDays09 slides : If you build it, you’ll ship it

As Dennis Doomen, I was quite happy with how the session went. Some stuff went by pretty fast, mainly because I did not want to present how the tools I used work, but did want to show the audience how I did it and what the tools are capable of.

Here’s the presentation if you’d like to review it and I’ve created a package with the demos as well. It contains…

  • NerdDinner for Visual Studio 2008 in folder structure as specified in presentation
  • FinalBuilder 6 script for building NerdDinner
  • FinalBuilder 6 script for deploying a ClickOnce application as described in this article.
I’ll be speaking at the Microsoft Developer Days 2009

Thanks to the many votes we received on our wildcard proposals from attendees, colleagues and community members, Pieter Joost van de Sande, Dennis Doomen, Michael van der Veeken and me have won a timeslot on next week’s Microsoft Developer Days. I’ll be talking about creating a build and doing continuous integration on Friday May 29th at 15:00 in the conference room named South America.

I will be showing how you can do continuous integration with the new abilities that Visual Studio 2010 has for this. I’ll also be showing other tools that can help you and give you best practices and pitfalls on continuous integration.

Why developers should not be happy with a project manager

I’ve been on a fair amount of projects in the past 10 to 15 years and almost all of them were waterfall. I’ve become really, really great in being able to tell if a project will fail soon or later. Not sooner or later, but soon or later. My weakness however is that I’m not really able to tell how to really run a project. I have some ideas that I preach, but it’s very rarely that I’ve been able to practice these. Of course it’s not my job, but it’d be nice to be able to tell others from experience.

I’ve just read Scrum and XP from the trenches and thought this was a great book. One thing I noticed however was when Henrik Kniberg was saying that the product owner gets to choose priority of the stories, but the team says how many stories go into a sprint. Kniberg describes how the product owner can influence this by altering stories or priorities, but the team sets the estimated velocity and thereby selects how many stories go into a sprint.

This reminded my of Microsoft Solution Framework, where in a team with different roles, there’s always the product manager and the program manager. These roles can never be filled by the same person. Putting it simple, the first role is there to make sure the customer gets what he wants. The second role is to make sure the team isn’t stressed out, can do their job, etc. That’s why the title of this post says “a project manager”, which is the opposite of “multiple” :-)

On every single project I’ve been on, I’ve always only had a single project manager. There are of course good project managers that really take care of the team. But because of various reasons, there’s always much more work than was originally planned and with this and various other reasons, the development team suffers by doing lots of overtime.

But with the simple rules stated above for both Scrum and MSF, the development team is (to some degree of course) protected from being burned down completely by doing so much overtime, that the people, the code and as a result the product, suffer greatly.

Very soon I’m going to start a new project at a customer and will really try to practice Scrum, sprints and daily scrums that take 15 minutes at max. Maybe I’ll blog about the experiences so people can learn from it or give me some hints on what we should do. The people involved so far are also pretty anxious to use Scrum and some XP practices for this project, so we’ll see where this ends.

Conclusion so far however is that if you have only one role that mainly keeps track of some Excel sheet but hardly protects the team for overload of stories, use cases, function points, features or whatever you may call them, perhaps you should look for another job… erm, project manager.

DevDays wildcard proposals and voting

Because it’s not clear to anyone, I want to state that you don’t have to actually be a visitor of the DevDays to be able to vote on the sessions. The only thing you need to do is register for an account, verify your email address by clicking on the link in the email you receive and you’re allowed to vote. Don’t forget to vote for my session.

Almost all companies use a source control repository to work in a team, but a lot of those don’t use Continuous Integration (CI) to…

  • Commit code at least once a day
  • Verify everything still works by running unit tests on an integration machine
  • Deploy databases and set up test databases for integration tests
  • Create deployment packages for test, acceptance and production environments
  • Be able to verify what the status of the project is
  • Deploy any day, any time

That’s what I want to explain and show during the developer days. If you want to know more about this, vote for my session.

Dennis Doomen will also be able to present you with a great presentation on Test-Driven Development and SOLID principles by Robert C. Martin (Uncle Bob) if you vote for him too.

On a site note, it’s funny how I sometimes see the ranking of both sessions drop. Some people seem to vote on a friend or colleague and give a thumb down on my and Dennis Doomen his session. Although it might be tempting to make all our thumb up voters also give a thumb down to all other sessions, it’s also a pretty sad. So giving me the thumb up will do, thank you. :-)

Asserting private objects with unit testing

There’s a lot of discussion going on about designing for testability. One of the problems of unit testing your code is that you might want to insert a fake object (like a stub or mock) so that your code under test won’t actually call out to the database or an external logging class. You can solve this by Inversion of Control (IoC) and using Dependency Injection (DI). You insert an object you want to isolate or an object you want to do assertions on via the constructor or properties.

Typemock Isolator also has a very powerful feature where you don’t have to use dependency injection. Let me be clear on this before you continue reading : you don’t have to. I know with Isolator you might not even need DI but it’s still a good practice to decouple dependencies. But I personally think it’s a bit sad that you need to change your design and use DI just because else you would not be able to write your test. And that’s where Isolator can help us.

Imagine we have to following code. A class called “SomeClass” with a method called “SomeMethod” that we want to test. This method however creates an instance of the “ClassWithProperties” class. Our method will fill this object and we really want to see what happened with this object. We want to verify it using tests. We’ve got different tests to test “ClassWithProperties”, but we want to know if the few lines of code that work with this extra class is doing what we expect it to do.

public class SomeClass
{
    public void SomeMethod(string name, int age)
    {
        ClassWithProperties cwp = new ClassWithProperties();
        cwp.Name = name;
        cwp.Age = age;

        // Start processing, calling ServiceAgents, whatever...
    }
}

public class ClassWithProperties
{
    public string Name { get; set; }
    public int Age { get; set; }
}

A real life example of this, for me at least, was where an Order object was created and filled with order lines and customer information and I wanted to assert the flow inside the method and if the object was filled correctly. Was the Order object indeed filled with the correct information?

We can insert the ClassWithProperties object via DI or use a ServiceLocator but why do that if you have a powerful framework? Using Reflective Mocks, the ‘old’ way (since there’s a much better API now) we could do the following.

[TestMethod]
public void CanWeGrabInternalObject()
{
    // Arrange
    string name = "Dennis";
    int age = 34;

    Mock mockedClassWithProperties = MockManager.Mock<ClassWithProperties>();

    // Act
    new SomeClass().SomeMethod(name, age);

    // Assert
    var result = mockedClassWithProperties.MockedInstance as ClassWithProperties;
    Assert.AreEqual(name, result.Name);
    Assert.AreEqual(age, result.Age);
}

What you see here is that a Mock object is created at line 8, which could be described as a fake version of our ClassWithProperties. We then make the call to “SomeMethod” at line 11 and pass two arguments that is mapped onto the class that’s created inside “SomeClass”. However using MockManager.Mock we make sure future instances are replaced by our fake object. When the call to “SomeMethod” is done we can retrieve the instance that our fake object is at line 14. We can then easily assert its current state and see if everything was correct. The Reflective Mocks is however not the most easiest way to go, although it’s still very powerful.

The Triple-A or ArrangeActAssert API is since Isolator 5.0 the way to go because of cleaner unit tests and its API is also much easier to understand. In our example we’d get the following result.

[TestMethod]
public void CanWeGrabInternalObjectWithNewAPI()
{
    // Arrange
    string name = "Alex";
    int age = 37;

    var fake = Isolate.Fake.Instance<ClassWithProperties>();
    Isolate.Swap.NextInstance<ClassWithProperties>().With(fake);

    // Act
    new SomeClass().SomeMethod(name, age);

    // Assert
    Assert.AreEqual(name, fake.Name);
    Assert.AreEqual(age, fake.Age);    
}

In line 8 we create the fake instance but nothing happens with future instances. If we’d use DI we could inject our fake object. As we’re not, in line 9 we’re making sure the next instance that’s created is swapped with our fake object. As you can see this is exactly the same behavior as the first test we wrote, but it’s much more clearer on what’s happening. We then call “SomeMethod” and make the same assertions.

However we’re now interfering with everything that’s normal to this ClassWithProperties. Constructor and other methods aren’t called. When we do want the class to act as usual, ie. be able to execute methods on it, we need a different approach. The "Isolate.Fake.Instance” method has an overload that allows us to supply an argument what the fake object should actually do. We can use Members.CallOriginal on it to make it behave like before. However that will also destroy our ability to check the state of the swapped object.

This is where we can perform a little trick though. Now that we have access to our fake object, we can redirect every call to this fake object to an object of our liking. We don’t even have to use a fake object. Hence the following test.

[TestMethod]
public void CanGrabFakedObjectAndRedirectCalls()
{
    // Arrange
    string name = "Marco";
    int age = 33;

    var fake = Isolate.Fake.Instance<ClassWithProperties>(Members.CallOriginal);
    var original = new ClassWithProperties();
    Isolate.Swap.NextInstance<ClassWithProperties>().With(fake);
    Isolate.Swap.CallsOn(fake).WithCallsTo(original);
    

    // Act
    new SomeClass().SomeMethod(name, age);

    // Assert
    Assert.AreEqual(name, original.Name);
    Assert.AreEqual(age, original.Age);            
}

Here you see that with the creation of the fake “ClassWithProperties” object, we specify that we actually want to call the original object. You normally do this, for example, when you want to verify specific calls on the object, set expectations on only a few method calls and/or want to redirect one or more calls. And that’s what we do, but we’re redirecting all calls. And we redirect them to the variable we call “original” in this test.

This will make sure, everything that’s happening on the fake object will get redirected to the object that we initialized, maintain and eventually assert in our test. Again, simple state based testing, although less elegant than the first test with reflective mocks.

Now of course there’s also a different way and speaking of elegant code, this is also technically better. And although I love state based testing over verifications (because most of the time it’s more readable), this last test is probably the nicest there is right now.

[TestMethod]
public void UseVerificationsOnObject()
{
    // Arrange
    string name = "Mike";
    int age = 35;

    var fake = Isolate.Fake.Instance<ClassWithProperties>(Members.CallOriginal);
    Isolate.Swap.NextInstance<ClassWithProperties>().With(fake);

    // Act
    new SomeClass().SomeMethod(name, age);

    // Assert
    Isolate.Verify.WasCalledWithExactArguments(() => fake.Name = name);
    Isolate.Verify.WasCalledWithExactArguments(() => fake.Age = age);
}

As a conclusion, there seem to be a lot of options with Typemock Isolator. Two remarks have to be made here. First of all, Isolator is so powerful that sometimes problems can have multiple solutions to it. This isn’t always what you want, as this makes finding the best solution harder. Especially when you don’t know what the best solution is, even though you know all possible solutions. Luckily with the new AAA API it’s much more clearer on what path to take.

As a second, for these tests, I’d say the last one is the best, because it’s best at revealing all the intention, one of my favorite rules of TDD by Kent Beck in his Extreme Programming Explained.

Wildcard proposal : If you build it, you’ll ship it

Every developer is familiar with the phrase "It works on my machine". But what if you could claim your code can be deployed at any time of the day? Simply because the latest tested and verified version has been prepared for you on your build server. Not to mention with separate installation packages for both testing-, acceptance and production environment?

If you would like to know how you can set up such an environment using the best tools and the best practices, vote for me at the DevDays site and let me tell my story in one of the two wildcard sessions.

I’m going to be talking about how to setup a build and use continuous integration to build the code, verify all unit tests and integration tests, build packages for all different environments and servers and setup configuration for each of them. We’ll do this using Team Foundation Server, MSBuild, FinalBuilder and more and also list a lot of the common tools used. Also discussed will be how to setup each environment and how virtualization can help you set these up. After visiting this session, you’ll know the best practices but also some of the anti patterns of continuous integration.

And if you want to know how you can get cake at work, every day, vote for my session and some see it.

Silverlight 3 SDK Beta 1

Via Twitter @MarcelMeijer and SDN site, that Silverlight 3 SDK Beta 1 was just released, a few hours before Mix09.

Best developer tools

Because of the nature of my work, coaching people on-site and training people in classes, I talk to a lot of developers and managers about the way people work. Unfortunately a lot of companies still don’t unit test their software and don’t setup an automated build. At times that’s specifically what we at Class-A are hired for. But if it’s not, we try to convince our customers that they gain by working with these practices.

Most companies want to professionalize and create better (quality) software. But for some reason, this can’t cost them anything. And I’m not talking about development time or learning curve, that’s a different story. I’m talking about the licensing cost of the tools you want or even need. For some reason people can’t lay down a few hundred dollars for something that will save them immense amounts of time, and thus money.

People rather spend countless number of hours on creating their own grid, whereas for a small amount of money you can buy a grid that has it all and can do it all, before you started thinking about it. People rather spend countless number of hours writing extra code, just to make it testable. People rather spend countless number of hours doing stuff that can be automated, generated or in some other way be helped with. I’m not sure about you, dear reader, but on my part this is unacceptable.

This blogpost is about my top 3 favorite products for developing software. Each one of them costs money, while there are free alternatives. But they’re in this list because they make developing software so much easier, that they pay back the investment within a matter of weeks or sooner.

 

  1. FinalBuilderMainScreenshot FinalBuilder
    This is a tool to setup automated builds via a really great user interface. It has over 600 actions to perform, like copy files, compile projects, source repository actions, archiving, flow control, etc, etc.

    With FinalBuilder you can setup these actions as steps and use advanced flows to guide builds through your steps. Work with variables, action panes with arguments that kind of behave like methods and much more. When a customer uses FinalBuilder, we try to automate everything; from build to deploying applications, services, databases and more.

    The best part is that everything works with a great user interface, instead of the XML files that MSBuild & TeamBuild use. It’s really easy to track down what happened if things go wrong as FinalBuilder includes (historical) logs, also visualized. And if you’re using Team Foundation Server 2008, there’s a great integration so you can start using FinalBuilder from within TFS. And if you don’t have TFS or a useful Continuous Integration server, you can use FinalBuilder Server.

    If you still setup a build without FinalBuilder, I urge you to download the trial and see for yourself how powerful and user friendly it is. And if you need help, you know where to find me.

    http://www.finalbuilder.com/
  2. Typemock Isolator
    typemock More and more people start writing unit tests and eventually start using a mocking framework. Although there are more frameworks and they’re even free, in my experience it’s unbelievable how powerful Typemock Isolator is.

    A great feature about Typemock Isolator is also that you don’t specifically have to design your code to be testable. Of course it’s a good practice to decouple using interfaces and what else. But if you need to decouple, using IoC and such just because else your code would not be testable, it’s not a good thing. You need those things for a good design, not a testable design. That’s where Typemock Isolator can help, simply because of its power. A few examples:

    1. You can swap out instances you normally can’t control from the outside and even use duck-type swapping.
    2. The SharePoint object model is extremely large, but Typemock Isolator makes it easy to create fakes by using a feature called Recursive Fakes. More info here.
    3. Scott Hanselman believes in it as well, as you can read in this case study.

    http://www.typemock.com/
  3. Refactor! Pro
    refactor There are multiple, so called, productivity tools. One of the most well known is Resharper, which I have a dislike for. First of all, it messes up my Visual Studio completely, which means my students won’t know when Resharper is doing something and when Visual Studio is doing something. You also have DevExpress CodeRush, one I like far better, but also changed Visual Studio a lot.

    Refactor! Pro is a tool, also by DevExpress. This tool doesn’t invade into Visual Studio too much, but has a great power for refactoring. You have to learn how to use the tool, as there still aren’t many small tips on the DevExpress website, which I think is a shame. The fact that you not only have to know which refactorings are available, but also where to place the cursor to enable the refactoring. But when you do learn, it gives you great advantage, especially when doing Test Driven Development where you have to refactor a lot of code.

    Again, a great tool to enhance productivity which eventually pays itself.

    http://devexpress.com/refactor/

Again, if you really want to gain in productivity and think this is worth money, buy these tools.

If you want to lag behind, have less control over what you’re doing and don’t think quality is something your customers need, don’t…

Azure and Virtual Machine hours

I suddenly remember that Azure can supply you with analytics on how your services and storage is doing, so I wanted to check this. Some funny results came out of this.

First of all, these statistics are about my speed traps application I blogged about before. It’s nice to know what it actually does.

  1. The application is running two roles:
    1. A web role for displaying an HTML page to the users with all speed traps. This role also has a WCF service running in the same web role.
    2. A worker role for retrieving the speed traps from my external source.
  2. The application itself checks every 10 minutes if there are speed traps available. No matter if it finds any, it deletes all entries in the database and stores all found entries in the database again.

So here are the statistics for my service and my website. Urls can be found in the previous post.

vmhours_hourly_usage vmhours_daily_usage

In the left image you can see the number of VM hours used every hour. This means that every hour of the day, I use up 4 hours of VM usage. This results in 96 VM hours per day. Which is kind of weird, as you get a max of 2000 VM hours per trial-key, which means my service should not be able to run for 21 days straight. Meaning that my speed traps service should start failing any day now! Here’s how…

We have the production and staging environment. The staging is of course to test if your application works, so you can more confident release it to production. For every environment you can have both a worker role and a web role. Both of these have, as Microsoft states, their own virtual machine. So as I ran one production version with both a web- and worker role, I use up two virtual machine hours per hour. But as I still had my staging environment running as well, I was using up 4 virtual machine hours per hour. And as you get 2000 VM hours per token you receive from Microsoft, my service won’t be running for 21 days straight. So I immediately suspended and deleted my staging environment, hoping I can now extend my speed traps service for 5 more days. ;-)

The following two pictures are about my storage. In the left image you can see the daily network usage in megabytes. Per day I transfer a maximum of about 2 megabytes. On the right side you can see the daily storage usage in megabytes as well. The funny thing is, as I’ve told, that every time before I store the latest speed traps, I delete all current available in my table storage. But still I use up to 40 MB of storage per day. Is that accumulated? No idea.

storage_networkusage storage_mbstored

Attach to debugger script and shortcut

I got sick of manually attaching to the webserver (either aspnet_wp.exe on WinXP or w3wp.exe on Win2003 or later). You can have a macro for that, incl. a shortcut key. I got this from somewhere on the web, but forgot where. If I find out, I’ll of course post it here. But I constantly have to search my sent items in Outlook for this bit of script when I tell someone about this. So here it’s on my weblog.

  • Press ALT-F11 (Macro IDE)
    A new Windows pops up
  • In the Project Explorer on the left, choose "Add new Item"
  • Choose a Module and name it "AttachToWebServer"
  • Paste the code below (and overwrite anything that was already there)
  • Close this Window
  • In Visual Studio, do "Tools" -> "Options" -> "Environment" -> "Keyboard"
  • In the textbox for "Show commands containing" type "AttachToWebServer"
  • In the "Press shortcut keys" press ALT F10
    It's currently bound to something you're not using anyway ;-)
  • Press "Assign" and "Ok"

Now go to your web application project and press ALT+F10 and you're in debug mode, attached to the webserver. Press F5 in your browser (of course in the correct website) and you're done!

Here’s the code:

Imports System
Imports EnvDTE80
Imports System.Diagnostics
 
Public Module AttachToWebServer
 
    Public Sub AttachToWebServer()
 
        Dim AspNetWp As String = "aspnet_wp.exe"
        Dim W3WP As String = "w3wp.exe"
 
        If Not (AttachToProcess(AspNetWp)) Then
            If Not AttachToProcess(W3WP) Then
                System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
            End If
        End If
 
    End Sub
 
    Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
 
        Dim Processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
        Dim Process As EnvDTE.Process
        Dim ProcessFound As Boolean = False
 
        For Each Process In Processes
            If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = ProcessName) Then
                Process.Attach()
                ProcessFound = True
            End If
        Next
 
        AttachToProcess = ProcessFound
 
    End Function
 
End Module
More Posts Next page »