Multiple projects – multiple repositories

April 26, 2008 on 9:00 pm | In SVN | No Comments

Do you have one project you want to share between multiple solutions? Something like a big set of helpers or a framework you need here and there? There are multiple ways ones have achieved this goal. Let me describe how I’ve done this.

We work with Visual Studio as our main development environment and Subversion as our source control system. What we needed was a systematic approach where we share our framework across all of our projects. We are actively developing our framework so simple dll reference is not an option. Our rules according to framework development make it fairly save to share the same code across multiple projects and to develop at the same time.

We decided that the framework should by placed in separate SVN repository and a separate Visual Studio project. But we wanted the framework and the project being pullable from source control as a whole. Firstly because we are (I’m!) lazy and I don’t want to remember that I have to check out the framework and than the project separately. Secondly we have a living Continuous Integration system running on CruiseControl.NET and it should by able to detect the changes and build to project in one shot.

Our way is to add the framework as an existing project from separate solutions…

Project structure

and to connect the main SVN project repository with framework repository as a svn:external.

Folder structure

Step by step solution:

1. Create “Framework” Project in Visual Studio

2. Create a SVN repository for this project (check everything you need in)

3. Create new solution in Visual Studio that will hold your “Project”

4. Create a SVN repository for this project

5. Create new folder on hard drive inside the “Project” folder

6. Check out the framework from repository into newly created folder

7. In Visual Studio add the framework to you solution as a existing project.

Adding exisitng project

8. Link the Framework repository with the Project repository (using svn propset or with TortoiseSVN like this)

svn:externals

You are done!

Now if you check out the “Project” you will get the “Framework” automatically. Unfortunately if you will make changes into “Framework” you will not by able to checkc everything in. You will have to separately check the “Framework” changes and “Project” changes. But if you are using Tortoise SVN you will by warned.

TortoiseSvn externals warning

Is is cool or not!?

Aiding your work with Visual Studio Code Snippets

April 16, 2008 on 7:35 pm | In Uncategorized | 2 Comments

I’ve bin writing //TODO comments in my code every time wondering what pattern have we agreed upon in our team. Was it a

// TODO Recipient Priority Sender, Message

or

// TODO Priority Sender Recipient, Message

or something else.

Today I thought: who am I to remember all those dentils? Do I have something to help me with this burning problem?

Well I have. The name is Visual Studio Code Snippet. It in a XML file that describes a quickly insertable text. With such XML description I will by able to write only a word “todo” in my VS and everything else will happen automagically. There will by a nicely highlighted input places allowing me to navigate with a Tab key to complete my //TODO comment.

Here is how to create such file:

1. create a XML file with snippet extension

2. the root element name is CodeSnippets

<CodeSnippets
        xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <!--Insert code snippets here-->
</CodeSnippets>

3. insert one or more code snippets in a tag named CodeSnippet

<CodeSnippet Format="1.0.0">
        <Header>
        <!--Header tags-->
        </Header>
        <Snippet>
        <!--Snippet tags-->
        </Snippet>
</CodeSnippet>

4. define your header

<Header>
        <Title>ToDo Comment</Title>
        <Shortcut>todo</Shortcut>
        <Description>Inserts todo comment</Description>
        <Author>Marcin Kawalerowicz</Author>
</Header>

The Shortcut tag is interesting. With this tag you will by able to define a short cut that will trigger your snippet. After this definition you will by able to write simply “todo” in your VS, then press Tab key an the magic will happen.

5. Define your Snippet

<Code Language="CSharp">
        <![CDATA[// TODO $Recipient$ $Prio$ $Sender$, $Message$]]>
</Code>

6. Do you see the variables between $ you have to declare them too

<Declarations>
        <Literal>
              <ID>Sender</ID>
              <ToolTip>ToDo sender</ToolTip>
              <Default>??</Default>
        </Literal>
        <Literal>
              <ID>Recipient</ID>
              <ToolTip>ToDo recipient</ToolTip>
              <Default>??</Default>
        </Literal>
        <Literal>
              <ID>Prio</ID>
              <ToolTip>Priority</ToolTip>
              <Default>0</Default>
         </Literal>
         <Literal>
              <ID>Message</ID>
              <ToolTip>Message</ToolTip>
              <Default>!</Default>
              </Literal>
         </Declarations>

7. Voila you are ready. You have to import this file to Visual Studio using Tools -> Code Snippet Manager… and the Import… button.


Now press Ctrl+K+X and you can browse to your new snippet or write simply “todo” and press Tab to see something like this:

image

Here is a complete code of our snippet (with NOTE comment snippet a a bonus ;)

<CodeSnippets
        xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
                <Header>
                <Title>
            - NOTE Comment
            </Title>
                        <Shortcut>note</Shortcut>
                        <Description>Inserts note comment</Description>
                        <Author>Marcin Kawalerowicz</Author>
                </Header>
                <Snippet>
            <Declarations>
                <Literal>
                    <ID>Message</ID>
                    <ToolTip>Message</ToolTip>
                    <Default>!</Default>
                </Literal>
                <Literal>
                    <ID>Sender</ID>
                    <ToolTip>Sender</ToolTip>
                    <Default>??</Default>
                </Literal>
            </Declarations>
                        <Code Language="CSharp">
            <![CDATA[// NOTE $Sender$, $Message$]]>
                        </Code>
                </Snippet>
        </CodeSnippet>
    <CodeSnippet Format="1.0.0">
                <Header>
                <Title>
            - ToDo Comment
            </Title>
                        <Shortcut>todo</Shortcut>
                        <Description>Inserts todo comment</Description>
                        <Author>Marcin Kawalerowicz</Author>
                </Header>
                <Snippet>
            <Declarations>
                <Literal>
                    <ID>Sender</ID>
                    <ToolTip>ToDo sender</ToolTip>
                    <Default>??</Default>
                </Literal>
                <Literal>
                    <ID>Recipient</ID>
                    <ToolTip>ToDo recipient</ToolTip>
                    <Default>??</Default>
                </Literal>
                <Literal>
                    <ID>Prio</ID>
                    <ToolTip>Priority</ToolTip>
                    <Default>0</Default>
                </Literal>
                <Literal>
                    <ID>Message</ID>
                    <ToolTip>Message</ToolTip>
                    <Default>!</Default>
                </Literal>
            </Declarations>
                        <Code Language="CSharp">
            <![CDATA[// TODO $Recipient$ $Prio$ $Sender$, $Message$]]>
                        </Code>
                </Snippet>
        </CodeSnippet>
</CodeSnippets>

Powered by WordPress with Pool theme design by Borja Fernandez.
Text © Marcin Kawalerowicz. Hosting CODEFUSION.