Quickly Create Test Solutions by Scripting the Dotnet CLI
From time to time, I need to create a small C# or F# solution to experiment with a code feature or a library function. Often, what I want to do is create a simple console application and a unit test project that references the console application. This isn’t hard to do in Visual Studio, but it feels like it takes too many steps.
Recently, I read a fantastic new book called Essential F#, by Ian Russel. (You can get it here) In it, he showed that you could quickly create the setup I described above with the dotnet CLI. It was an idea so brilliantly simple that I’m jealous that I didn’t think of it. But I did take it a step further and created a bat file to further automate the process.
The commands in this script are taken directly from the book. The only modification I’ve made is to parameterize the solution name and the project name.
With this script, you could execute something like this command:
CreateFSharpProject SampleSolution SampleProject
This would create a new Solution named SampleSolution. It would contain two projects F#, SampleProject and SampleProjectTests. The test project already has a reference to the primary project and is ready to execute the tests with FsUnit.
I created a similar script file for C# and MSTest.
With these scripts, you can quickly create solutions with the unit test project already configured. That way, you can jump right into the code experiment you want to run.
You can take this concept and modify it to create whatever kind of project and unit test project you want. Hopefully, it is a simple little time saver for you.
Comments Section
Feel free to comment on the post but keep it clean and on topic.
comments powered by DisqusAbout Me
My name is Eric Potter. I have an amazing wife and 5 wonderful children. I am a Microsoft MVP for Developer Tools and Technologies, the Director of Technical Education for Sweetwater in Ft. Wayne Indiana, and an adjunct professor for Indiana Tech. I am a humble toolsmith.
pottereric.github.com