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.
- Unload the "Client" project ( Right click on the "Client" project and select "Unload Project" )
- Once unloaded, right click on the unloaded "Client" project and select "Edit Client.csproj":
- 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.
- Save the project, then reload.
- You'll be presented with this dialog:
- Click on the "Load project normally" and click OK.
- Now drag the "FirstLayerDiagram.layer" file from the "Diagrams" solution folder into the "Client" project.
- Delete the "FirstLayerDiagram.layer" file from the solution folder.
- Select the "FirstLayerdiagram.layer" file that is now in the "Client" project, and set its "Build" action to "Validate":
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" />
<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 ):
- 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!