Today I’ve been fixing up the build system for Microsoft.Activities and Microsoft.Activities.UnitTesting. Over time I’ve been using a combination of strange tools and batch files to build things but it became such a mess I decided to take the time to finally build a good project file that I can use MSBuild on that will do everything
- Build sources
- Build Help files
- Build NuGet Packages
The first problem I ran into was that my unit tests use the [DeploymentItem] attribute to deploy files when testing with MSTest. The problem is that the test considers the $(SolutionDir) the root folder for the test. Previously I had just the Solutions for Microsoft.Activities and Microsoft.Activities.UnitTesting but now I made a single solution file in a different location with everything. This cause my tests to be broken because the deployment paths were wrong.
After much searching I finally decided the best thing to do was to use an environment variable. Since I call these projects “Labs" projects (for historical reasons) I decided to use a variable called “LABDIR”.
Now I can get my items deployed successfully regardless of where the solution file is opened.
But then, what if I try to build on another machine where LABDIR is not set? I decided to modify the Test Project so that it will fail the build if the variable is not set. Ok – search engines take note of the following question so that the next guy searching for this can find it.
How do I cause a build failure if an environment variable is not set?
Just add this to the end of your Test project .csproj file
Now if I try to build the test project without LABDIR set, I get this.
Error The LABDIR property must be set on the command line or environment variable must be supplied.