Friday, January 9, 2009

Setting up an ASP.NET MVC Project using TortoiseSVN and Unfuddle – 2. Creating the VS Solution

So Far

In the last post, I walked through the steps to create the folder structure and checking it into my Unfuddle repository. Now we will pick up from there and create our Solution file, MVC/Test projects, verify it builds, and check that into the Unfuddle repository as well.

A few prerequisites

  • Visual Studio 2008 – SP1
  • ASP.NET MVC Beta
  • XUnit – with the Visual Studio plugin installed (you could do this with MS Test as well)

Creating the Solution File

When creating a new solution I lean toward setting it up first using a Blank Solution so that I have a little more control over the process. You can just let it create it automatically when you create the MVC Project but you don’t get as much control over the folder structure within your project and may need to go back and manually move things anyway. I just do it as I go.

Open Visual Studio and click on File –> New –> Project

Once it opens select Visual Studio Solutions under Project Types.

Then select Blank Solution, enter the solution name, enter the path in your local repository coresponding to trunk\src and click OK.

Snap10

Now this what gets created:

Snap11

You will notice that the sln file was created in a new mymvcsolution folder which I really don’t want. I will just close Visual Studio, cut the files and paste them into the src folder and then delete the unwanted folder. ALl the mappings within the file are relative so once the files is moved all is good.

Create the MVC/Test Projects

Now click on the sln file to reopen Visual Studio.

Click on FIle –> New –> Project

Snap12

Under Project types select Visual C# –> Web and the ASP.NET MVC Web Application.

Enter mymvcapplication for the name, verify that it is using the trunk\src folder as the Location and for Solution it should use Add to Solution.

You should now get the following prompt:

Snap13

I have selected xUnit but you could also go with MSTest at this point .

Now if you try to build at this point you will get 5 identical fails:

“The name 'GlobalApplication' does not exist in the current context   C:\projects\mymvcproject\trunk\src\mymvcapplication.Tests\Routes\RouteFacts.cs”

When you navigate to the code you will find the following:

   1: GlobalApplication.RegisterRoutes(routes);




The problem is that the GlobalApplication is named MvcApplication in Global.asax.cs. If you update this in each of the tests to:





   1: MvcApplication.RegisterRoutes(routes);




Then build again it will all be successful.


 


A Little Tuning



If you look in the trunk\src\mymvcapplication.Tests folder you will find a folder called 3rdparty and remember we created a folder in the trunk called thirdparty. When I add more test projects I will either need to reference this file or have another copy of this file in each project. I would prefer to move this to the folder I created for this purpose. So I will cut the xunit.dll from this folder and paste it into my thirdparty folder in the trunk.


 


Then I will delete the 3rdParty folder from the test project.


One last thing I need to do is in Visual Studio in the references, I need to remove the current xunit reference and add the new one by right clicking on references


Snap14


Click Add Reference:



Snap15



Click on the Browse tab an d navigate to the trunk\thirdparty, select xunit.dll and click OK.



If you build the solution now you will find it builds fine.



If you want to see success hit F5 and click ok on the warning to enable debugging in your web.config. You will see this:



Snap16



Now I will close Visual Studio and Check in.



Checking In



I will now navigate to the trunk folder and right click on the mymvcproject(root) folder and right click on the trunk folder and click on SVNCommit:



Snap17



I will then click the select all box but then deselect the contents of the bin folder, add a message like “Initial Project Checkin” and click OK. The following dialog will show the files being added and uploaded and the success message (hoepfully):



Snap19 



Now when I open Unfuddle and check the repository I see the files I checked in so we are done!



Ok well done is a strong word really we are ready to actually get started but now we have a place to work and if we check in religiously we have some backup for code changes and such.



Later I will visit how to set up a continuous integration server with CruiseControl.NET so that you can get validation that your checkins don’t break the build.



Please let me know any comments you may have.

No comments: