Incorporate Layer Validation in your Builds


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

Comments (8)

  1. Geek Noise says:

    Layer Validation with the VSTS 2010 CTP

  2. Erik Cox says:

    It’s nice to see how a professional explains things :)..I mean I regularly read all of your VSTS 2010 posts and try out everything you do in your posts..for me that is the easiest way to learn new things..and I gotta say I’m a fan…

    Erik Cox

    http://www.notionsolutions.com

  3. [Nacsa Sándor, 2009. január 19-31.] Ez a Team System változat a szolgáltatás-orientált (SOA) elosztott

  4. In Visual studio 2010 Team Architect edition, you have a new type of diagram available, called the layer

  5. As mentioned in previous posts a huge effort of the TFS Migration tools initiative was to reverse engineer

  6. BHardister says:

    Cameron, I tried getting layer diagram validation to work in the build for the beta 1 version. It’s not working. Validation from the diagram does work, but not in the team build (or msbuild). What I tried is this (as a delta from the procedure above)

    A. step 3 not needed (ArchitectureTools folder no longer there)

    B. step 10 did not perform the valiation

  7. Suhail Dutta says:

    Hey Bob,

    As of Beta1, steps 1 through 6 are no longer necessary.

    A couple of things to verify

    • Make sure that the layer diagram is not in the modeling project. You must put it in a code project e.g. C# class library
    • Make sure the build action is set to ‘Validate’. As of Beta1 this is the default, but we have some issues around copying files from 1 project to another.

    • Make sure you add project references to all the projects that you want validated.

    Since this validation relies on msbuild, we need to tell msbuild what projects should be analyzed. This is achieved by creating project references

    Often it is just enough to create a project reference to the client application which tends to be on the top of the project reference hierarchy.

    Hope that helps. If not, let me know whats going wrong – are you seeing any errors?

    Thanks

    Suhail

  8. BHardister says:

    Suhail, I had the LD validating between a console project and a class library. Once I changed the LD dependency between two class libaries it worked in MSBuild from the command line, but not in the team build. I tried passing in the /t:ValidateArchitecture parameter to the team build, but this did not work as it tried to apply the target to the solution not the project containing the LD.

    If I have it working in MSBuild from the cmdln for the project with the LD, it seems that MSBuild in the team build just needs to run the ValidateArchitecture target in the same way the cmdln is. Why doesn’t do this? I have set the build action property for the .layer file to validate and also for the .suppresion file under the .layer file. Why aren’t these property values being picked up by the team build?

    Thanks for your help!!