Far Away Developer

Sebastien Lachance

Archive for the 'Visual Studio' Category


Type Sharing in Visual Studio 2008

Posted by Sebastien Lachance on May 22, 2008

On a previous post called Reality of type sharing in WCF. I talked about a way to use existing types for a WCF service instead of the generated proxies. Previously, we were unable to do that in Visual Studio 2005, but it’s doable Visual Studio 2008.

Start by adding the library you would use for type sharing on the project you will add a service reference.

When you add a service reference, click on the Advanced… button.

addservicereference

 

Then, make sure the Reuse types in referenced assemblies checkbox is checked.

reusestypes

You can fine tune further, if you do not want to use some assemblies for type sharing.

And you are done!

Technorati Tags: ,

Posted in .NET, Visual Studio, WCF | No Comments »

My solution node does not appear in Visual Studio 2005 or Visual Studio 2008

Posted by Sebastien Lachance on May 13, 2008

A reader asked me how we can display the solution node in Visual Studio when you have only one project. This feature is turned off by default. What you need to do is to go in your Tools/Options menu and click on Projects and Solutions. Then you need to check the Always Show Solution checkbox.

AlwaysShowSolution

Feel free to ask me any questions.

Posted in .NET, Visual Studio | No Comments »

Screencast goodness

Posted by Sebastien Lachance on December 24, 2007

Here is the bests screencasts I have watched this week :

Monorail Quickly: A screencast made by Joey Beninghove (joeyDotNet). I have quite enjoyed this one. He has done a template project for quickly starting up a solution for Monorail.

A series of screencasts from colinramsay.co.uk :

A ton of new screencasts about ASP.NET 3.5 Extensions.

And I wish you a merry Christmas!

Posted in .NET, ASP.NET, Fun, Learning, Visual Studio | No Comments »

Congratulation to me!

Posted by Sebastien Lachance on December 12, 2007

I have just received this! The inscription is :

Thank you for the lasting contribution you made to Microsoft Visual Studio. S. Somasegar

Vs2008

I really like receiving gifts, but I would have preferred a free copy of Visual Studio 2008. :) . Anyway, It’s a nice thank you.

Posted in Blogging, General, Visual Studio | No Comments »

Basic Layout of my solution

Posted by Sebastien Lachance on December 6, 2007

(Index of the whole series)

I have completely forgotten to show you the basic folder hierarchy of my solution. I invite you to try once to make a completely different folder hierarchy instead of the one Visual Studio suggest. Not that Visual Studio is a bad tool for this, not at all. I have learned that letting a tool do the folder management can lead on to unnecessarily complexity. Let me explain myself. There is an adage that say you should program into a language instead of programming in a language. Make Visual Studio work with your layout instead of using the default. I find interesting what you can learn when you organize yourself the layout of the solution.

Anyway, let’s see my folder structure :

solutionstructure

The build folder is where the compiled application will reside. When doing automated testing I will use this version.

The config folder is where all the configuration files will be. I’ll probably get rid of it real soon as I have probably found a way that work better for me.

The lib folder contains library that are necessary for the project to be executed correctly.

The sql folder will contains all the sql script. This is also considered to be removed.

The src folder is composed of the app folder and the test folder. Each one contains a subset of all the projects (tests projects in the test folder and application in the app folder).

The tools folder contains any tools that are not necessary to execute the solution but are needed for the development.

It’s basically all I need for now to begin iterating on my application (using User Stories of course). I must mention that I doing this in an iterative way and a lot of things are subject to change. Any comments are greatly appreciated and will be read and considered.

I’m also considering to put all source file into Google Code. Stay tuned!

Posted in Agile, Continuous Integration, Design, Learning, Visual Studio | No Comments »

Setting up the build file

Posted by Sebastien Lachance on December 4, 2007

(Index of the whole series)

This is really easy on a new project! I think that the success on setting up a build file is going a step at a time. Unfortunately this is not always the case in some of our projects due to time constraints.

I am using NAnt for this.

Step 1. Deciding where I wanted to put my build.

Going with some advices I decided to go on the classic build folder. I make sure the folder is deleted and created back at every build.

 

 

<!-- Start by cleaning the build area -->
<target name="clean">
  <delete dir="build" if="${directory::exists('build')}" />
</target>

<!-- Create a build area -->
<target name="init">
  <mkdir dir="build"/>
</target>
Step 2. Compiling the project.
This is where the challenge lies. The csc Nant task is not aware of the .NET 3.5 framework. To get around this problem I have download a nightly build of NAnt 0.86. Works perfectly, until…

Remember I’m using WPF for my GUI. I was getting some strange errors about something missing in the System.Window. Full error :

[csc] Compiling 7 files to ‘C:\dev\LogItAll\build\LogItAll.exe’.
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\App.xaml.cs(13,32): error CS0246: The type or namespace name ‘Application’ could not be found (are you missing a using directive or an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(6,22): error CS0234: The type or namespace name ‘Controls’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(7,22): error CS0234: The type or namespace name ‘Data’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(8,22): error CS0234: The type or namespace name ‘Documents’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(9,22): error CS0234: The type or namespace name ‘Input’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(10,22): error CS0234: The type or namespace name ‘Media’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(11,22): error CS0234: The type or namespace name ‘Media’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(12,22): error CS0234: The type or namespace name ‘Navigation’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(13,22): error CS0234: The type or namespace name ‘Shapes’ does not exist in the namespace ‘System.Windows’ (are you missing an assembly reference?)
[csc] c:\dev\LogItAll\src\app\LogItAll.UI\Window1.xaml.cs(20,36): error CS0246: The type or namespace name ‘Window’ could not be found (are you missing ausing directive or an assembly reference?)

Humm, why is there something so obvious that it should be there failing? The reason is that some of the libraries required on a WPF project are not in the GAC. They are located in the C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\. Next, there is the problem that some file are generated and not always there, the InitializeComponent method is missing everywhere…. This is strange, how can I use csc.exe to generate those files? You can’t use csc.exe, when you use XAML ! After a lot of googling, I stumbled upon this MSDN page. I had no choice but start using MSBuild for the compilation.

So I changed my csc task to an exec task and called MSBuild. I was now facing the problem that the assembly are compiled and put in their respective folder. A little change to the Output path in Visual Studio 2008 did the trick. Note that I am not using it on all project. I’m only interested in the UI project and all the tests projects. They are all what I need to run the application and the unit test.

outputpath

This is what the NAnt section look like:

 

 

<target name="compile" depends="init">
    <exec
    program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
    commandline="LogItAll.sln"/>
</target>
3. Executing the tests.

 

 

<target name="test" depends="compile">
  <exec basedir="tools\mbunit\"
    useruntimeengine="true"
    workingdir="build"
    program="mbunit.cons.exe"
    commandline="LogItAll.Domain.Tests.dll /rt:html /rf:"."" />
</target>

I’m still trying to find a more generic way to execute all the test projects. As you can see I am using MBUnit as my unit testing tool for this application.

4. Result

 

 

<?xml version="1.0"?>
<project name="LogItAll" default="all">

  <target name="all"/>

  <!-- Start by cleaning the build area -->
  <target name="clean" description="remove all build products">
    <delete dir="build" if="${directory::exists('build')}" />
  </target>

  <!-- Create a build area -->
  <target name="init" depends="clean">
    <mkdir dir="build"/>
  </target>

  <target name="compile" depends="init">
      <exec
      program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
      commandline="LogItAll.sln"/>
  </target>

  <target name="test" depends="compile">
    <exec basedir="tools\mbunit\"
      useruntimeengine="true"
      workingdir="build"
      program="mbunit.cons.exe"
      commandline="LogItAll.Domain.Tests.dll /rt:html /rf:"."" />
  </target>

</project>

Posted in Agile, Learning, Tools, Visual Studio | No Comments »

Visual Studio 2005 : Reference Path

Posted by Sebastien Lachance on October 15, 2007

When I came across this feature, my world changed forever. When you are in a multi-user scenario and your assemblies are stored in a different folder from your peer, then you have this solution. Suppose you get the latest version from the project you are working on and the reference to AssemblyA is broken because the path of the assembly is C:\dev\lib. But you know that you have it in a folder somewhere else and you don’t want to duplicate that assembly. Then the reference path will come to the rescue. Adding a reference path will add a place that will be looked when checking for references. This is how you do it :

Step 1. In the solution explorer, right-click on the project with a broken reference.

Step 2. Click Reference Paths tab

Step 3. Enter the folder in which your assembly is located.

Step 4. Click the Add Folder button.

This is what it should look like :

Reference

Notice that you can also Update and Delete reference in this page.

Posted in .NET, Visual Studio | No Comments »

Visual Studio 2005 : Adding projects to your solution

Posted by Sebastien Lachance on October 11, 2007

There is 2 ways :

1. Begin by opening the New Project dialog box : File/New/Project… (or Ctrl-Shift-N). Navigate to the type of project you want. In the solution dropdown, choose Add to Solution. Failure to do that will result in the creation of a new solution. Enter the name of our project and click the OK button.

AddToSolution

2. In the Solution Explorer (Ctrl-Alt-L), right-click on the solution node and choose Add/New Project…

AddNewProject2

This time you don’t need to choose anything in the dropdown. Enter the name of the project and click the OK button.

Each one of those 2 methods will a a new folder with the name you entered. Inside the folder you will find a project file (.csproj or .vbproj) and a .cs (or .vb). By default Visual Studio will generate a default file for the type of project you choose).

Let’s look at the project file.

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>c50693b9-547b-49f0-8850-e3c0a3b0325c</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>ClassLibrary1</RootNamespace>
    <AssemblyName>ClassLibrary1</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

As you can see, it’s an xml file. It contains informations about the assembly name, the output type, namespace, version of Visual Studio used to create the project, etc. And it also contains the information used to compile. This is a whole topic so we will not cover it now. Right under we have the reference used by the project and the files it contains . You do not need to remember all that, the important thing is to know what is the purpose of the file. And finally, if you decide to use SourceSafe, all binding information will be added to this file.

Posted in .NET, Visual Studio | 3 Comments »

Visual Studio 2005 : Starting a solution correctly

Posted by Sebastien Lachance on October 10, 2007

I’m always wondering about what should I be blogging today. But not today. I want to give back some of the stuff I’ve learned in the past years. The question was : I’m starting with what? After some time, it struck me right in the face. I know that some people would prefer using notepad over Visual Studio, but I’m not there to discuss that. I found that mastering an editor is a great to get started and will allow you more time to code and less time to wonder where is the option that will highlight the file you are in. So the first posts will be about Visual Studio 2005. And the very first is about how to start a solution correctly.

Why?

Given the number of people I helped with that, I think this is something you should know. You should not start be creating a project. Doing that will lead you to a messy folder hierarchy and a wrong solution name.

When?

Everytime you start a solution.

How?

You start by clicking File\New\Project… or Ctrl-Shift-N.

FileNewProject

In tree on the left you need to go to the Other Project Types node and select Visual Studio Solutions. You now have the choice of selecting the Blank Solution item. You should notice that the checkbox for the Create directory for solution is grayed out, this means that a directory will be created for the solution. In our case, it will be : C:\dev\dotnet\Solution1. This folder will also contains a Solution1.sln and Solution1.suo. This is exactly what we want, every project you will add will be placed in this folder. The hierarchy you see in the Solution Explorer will be the same as your solution.

BlankSolution

.sln file

This is the solution file that Visual Studio will use to load all project associated with the solution. As well as other options that does not need to be covered now.

.suo file

This binary file contains information about what files were currently in edition, collapsed nodes, etc. When you close and reopen Visual Studio 2005, it will read this file to replace it the way it was before.

Posted in .NET, Visual Studio | No Comments »

First experience with Visual Studio 2008

Posted by Sebastien Lachance on July 28, 2007

Yesterday I downloaded the Beta 2 of Visual Studio 2008 and .NET 3.5. And I decided to start writing a little journal application. During the first hour I had not seen anything new and was wondering what are the advantages of migrating to 2008 if you are not doing Web Application (new features concerning CSS, JavaScript, debugging, etc..). I decided to do a quick search on Google, and found the ScottGu’s Blog (highly recommended) which was enumerating some new features. And found 2 that was directly applicable now to my application : Automatic Properties and Query Syntax.

Automatic Properties

Suppose you are writing properties for a class. Don’t you find that you are creating private field for nothing. Wouldn’t it be simpler that the compiler generate it automatically for you. Check this out :

public DateTime? EntryDate
{
   get { return _entryDate; }
   set { _entryDate = value; }
}

become

public DateTime? EntryDate { get; set; }

Less code means more time to do something else, so I’m happy!

Query Syntax

I had a collection of JournalEntry instance and wanted to find the one containing the date the user selected. The way I had done it at first was to iterate through the collection and check if the date was the same (I could have done it with predicate too). But the way LINQ handle it was too cool not to try it.

P.S One advice before you try this. Make sure the project is compiled using .NET 3.5 and you reference System.Core.

My little loop has became this :

IEnumerable<JournalEntry> results = from j in Journal
                                    where j.EntryDate == selectedDate
                                    select j;

Posted in .NET, Visual Studio | 1 Comment »

Javascript in Visual Studio Orcas

Posted by Sebastien Lachance on June 14, 2007

Now, I can’t wait to get my hand dirty with the next version of Visual Studio, Orcas. The javascript enhancements are just … incredible. You get intellisense (one that seem better than the current intellisense of Visual Studio 2005) and this intellisense can access your custom javascript library. You can add reference to a script inside an assembly. And the best part is coming … you can comment your function and they show on the intellisense. After reflection, it seems that all the features that interest me are about intellisense.

I know there is already some editor that can provide the same functionality, but as .NET developer using Visual Studio there is some advantages having it all in one place.

For a demo of all these features, go here.

You can get a list of all features specifications of Orcas, here.

Posted in .NET, Visual Studio | No Comments »

Visual C# Code Snippet collection

Posted by Sebastien Lachance on December 14, 2006

If you are using Visual Studio 2005 and C#, you should try the free C# Code Snippet collection from MSDN. I’m using it since the release (I know, I’m sorry, I should have you let it know sooner) and found them rather useful.

Posted in .NET, Visual Studio | No Comments »