As I promised in my last post, I want to show you how you can make Layer Validation part of your build process. I'm going to assume you've followed along from last post to make things easy. Again, this is all possible in the VSTS 2010 CTP.

  1. Unload the "Client" project ( Right click on the "Client" project and select "Unload Project" )
  2. Once unloaded, right click on the unloaded "Client" project and select "Edit Client.csproj":

    image
  3. Find this line:
     
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

    And add this line right after it:

    <Import Project=" $(ProgramFiles)\Microsoft Visual Studio 10.0\Team Tools\Architecture Tools\Microsoft.VisualStudio.TeamArchitect.Validate.Targets"/>

    This is a temporary step to make this work in the CTP. At RTM ( and even for Beta ), the new targets file will be part of the core MSBuild targets file.
  4. Save the project, then reload.
  5. You'll be presented with this dialog:

    image 
  6. Click on the "Load project normally" and click OK.
  7. Now drag the "FirstLayerDiagram.layer" file from the "Diagrams" solution folder into the "Client" project.
  8. Delete the "FirstLayerDiagram.layer" file from the solution folder.
  9. Select the "FirstLayerdiagram.layer" file that is now in the "Client" project, and set its "Build" action to "Validate":

     image
    Now if you did want to leave the "FirstLayerDiagram.layer" file in the "Diagrams" solution folder, you would have to manually edit the "Client.csproj" file, changing this line:

    <Validate Include="FirstLayerDiagram.layer" />

    to this:

    <Validate Include="..\FirstLayerDiagram.layer" />

    You're project would look something like this ( notice the little arrow overlay, indicating that this is a reference to a file elsewhere ):

    image

  10. Now at this point you could drop to the command line, assuming the Client.csproj file is in "c:\temp\Layer Validation\Client", and type "msbuild /t:ValidateArchitecture".

 

Ideally, it would be great to incorporate this step into the build process whenever you build the solution or Client project. You would do something like add a DependsOn="ValidateArchitecture" attribute to the "AfterBuild" target in the project file. Unfortunately, the same bug that requires you to refresh the Architectural Explorer after each build of the project will prevent this from working as it should. Clearly, this will be corrected by RTM.

Hope that helps!

Cameron