Sunday, 22 January 2012

C# with Visual Studio and Rational Team Concert (OSLC revisted) (Part 1)

I have had some recent customer experiences which have impelled me to write some blogs on the RTC Visual Studio integration. This topic follows the previous series well, where I wrote about RTC and CDT. In fact, I will will basically recreate the OSLC example ( this time using C# ) but using the Visual Studio 2010 development environment instead. Meaning that I will be using visual studio not only for developing but writing unit tests and doing a static analysis all while using the RTC visual studio integration.

If you recall in the previous blog series on OSLC, I created an OSLC client in C/C++ using CDT. I could do the same in Visual Studio (OSLC client using C/C++, that is) but I will instead use C# to create the OSLC client this time to show how this can also be done.

What You Need

This exercise may work with other versions of Visual Studio as the integration supports other versions as well but I will use Visual Studio 2010 .

I am also assuming that these are installed as well as:

Ensure that the CLM servers are setup correctly (at a minimum, CCM and JTS). Please refer to the CLM information center for how to do this. For reference my URLs and directories area as follows, you will need to replace them in this blog as appropriate for your environment:

JTS URL: https://tpborisk7:9443/jts
CCM URL: https://tpborisk7:9443/ccm
CLM install directory: C:\IBM\CLM3012
Sandbox: c:\vsworkspace
Setting up (creating project areas and solutions)

1. If you have installed your visual studio environment correctly, you can launch Visual Studio now. The Visual Studio RTC integration behaves very much like the Eclipse RTC integration. There are some key differences.

2. One of the differences is that it is not possible to create a CCM project area from visual studio. This will need to be done through the CCM web UI. Go to the project area creation page: https://tpborisk7:9443/ccm/

3. Create a new project area called OSLC and use the scrum template. Be sure to assign the user (in my case servadm) you will be connecting from Visual Studio as the “Scrum Master”.

4. Now connect to the project area using the Team Artifacts window:
5. Connect to the server:

6. Click next and select the OSLC project area we created and click "Finish". We are now connected.
(NOTE: You may need to "Load.." your repository workspace into your sandbox at this point in order to see the "Share solution in Jazz" option below.)

7. Lets create a new solution that we will use to develop our c# OSLC client.In Visual Studio select

8. Select a Console application under Visual C#->Windows->Console Application

9. Call the project OSLC Consumer and use a solution called OSLC (as we will created more projects in the future) in a preferred location. Make sure to select the "Share solution in Jazz" option.

10. Once you confirm your solution location you will be asked to select a sandbox. You should choose the sandbox location that we chose as the solution directory above. You can think of a sandbox as a collection of visual studio solutions/components under Jazz source control. So:

11. Lets create a new component for our Consumer called “OSLC”

12. Leave the defaults for the ignore files options. You should end up with the following directory structure (or similar):

13. In your pending changes view you should now see that we could deliver the new solutions with its project into jazz source control which we will do. Right click on the "Share Projects" and "Deliver" them into the OSLC Stream. (Click yes if it asks you if you want to deliver the component changes)

14. (If you understand component solutions relationships in VS skip to 17)
In anticipation of unit test we will eventually create lets create two more project skeletons. One called "OSLC Consumer Common"(containing common code) and a unit test project, "Test OSLC Consumer". Right click on the project and Add a project of type "Class Library"

15. Let's add the test project called "Test OSLC Consumer" of type "Test Project":

16. Unlike the solution there is not default option to add a project to Jazz Source control so we will have to do it now. Select both the new projects and right click and select the “Share Project(s) in Jazz...” option but do not click Finish!

Notice a key difference here between the RTC eclipse and Visual studio integration. The Component alignment is done at the solution level rather then at the project level! 
So in eclipse many projects are associated to a component, where in visual studio, many solutions to a component, where projects in the solution belong to the component of a solution.
In effect, if we wanted to have the unit tests, common code and consumer client in different components you would essentially need to create three solutions (one for each) in the sandbox. As this is exactly what we want this is what we will do (but you don't have to).
Just because we have three solutions does not mean we need to keep three IDE solution instances open because we can easily add the projects from different solutions to the same solution (which we will do.)
As I have gone through this detour to highlight this difference, lets revert and cancel out of the “Share Projects(s) in Jazz...”.. Right click on the two projects and select Right Click->remove. Also delete the corresponding directories on the file system. You will probably also want to delete the following files out of the solution directory: Local.testsettings, OSLC.vsmdi and TraceAndTestImpact,testsettings.

17. In anticipation of unit test we will eventually create lets create two more solution skeletons. One called "OSLC Common" with a project called "OSLC Consumer Common" (containing common code) and one called "Test OSLC" with a unit test project, "Test OSLC Consumer". As we want these in separate components lets create two solutions for these projects. We will create these solutions in the same sandbox as the "OSLC" Solution above.
18. First create the "OSLC Consumer Common" library which is a project of type "Class Library" in the "OSLC Common" solution:

19. Put it in the "OSLC Common" Component:

20. Delver the new solution and project to the OSLC Stream.

21. Let's repeat for "Test OSLC Consumer" library which is a project of type "Test Project" in the "Test OSLC" solution:

22. Now lets add it to the "Test OSLC" component:

23. Deliver the solution to the “OSLC Stream”

24. Go to the Solution Explorer Window (Team Concert->Windows->Sandbox Explorer).. it should looks as follows:

25. As i have named solutions the same as the Components we can easily see the projects in each component.
To avoid having to keep three IDEs open lets add the "OSLC Consumer Common" and "Test OSLC Consumer" projects to the "OSLC" solution by right clicking on the solution and Add->Existing Project...

26. Add the two projects and save the solution. You should have:

27. You can now deliver the OSLC.sln file to keep the changes to the solution. In the future we only need to open the OSLC solution. When you switch sandboxes Visual Studio will automatically ask you for a solution file. We will pick OSLC.sln from now on.

28. I have also gone ahead an deleted the default component and we might as well have the components be owned by the project level. Go to the “Team Artifacts” window and right click on the components and change ownership to the project for each component:

You project areas should look like this now:

This should prepare us for the next blog entry where we will start coding the OSLC client in C#.