Last week, on the last day of the MVP Summit, I participated in the .NET Hackathon. There were many different topics, ranging from ASP.NET Core to Minecraft and HoloLens. But I was interested in better understanding the .NET Core tooling so I joined the table of the dotnet-cli team.
With the move from the easily editable project.json file to the old .csproj format, it became more difficult to manually edit the project file, so I built a command for the dotnet cli, to make it easier to edit some properties without messing up with the XML-based format of the MSBuild file.
The usage of the tool is very simple. First you have to add the tool to the project you want to edit by manually editing the csproj file. I know this sounds a bit weird but unfortunately there is no way to add global tools for the dotnet-cli, but only tools specific for a project. I sent a pull request to the dotnet-cli project so this step won’t be needed if they include this tool as command.
To add the reference to the tool you have to add:
<ItemGroup> <DotNetCliToolReference Include="dotnet-prop"> <Version>0.1.0-*</Version> </DotNetCliToolReference> </ItemGroup>
Then, restore the dependencies and finally just call the dotnet prop verb from the root of project. The commands available are:
- add, to add a property (or update one that already exists)
- del, to remove a property
- list, to list all the properties of the csproj file
For the moment I only implemented the possibility to add/update the following three properties:
- version number (-v|--version), which sets the VersionPrefix property in the MSBuild file
- target framework (-f|—framework), which sets the TargetFramework property
- supported runtimes (-r|--runtime), which sets the RuntimeIdentifiers. Since one project can be built for many runtimes, this option can be specified more than once
You can find the code on my github repository: https://github.com/simonech/dotnet-prop/
The tool is available on nuget and will be automatically downloaded when restoring the packages of your project.
This was just a test and it’s a work in progress, so please let me know what you think of it, and which other properties should be added.
I’m also undecided on the right commands and options to use. Which of the following pattern do you think is better:
- command for the operation (add or delete or list) and option for the property (like now): dotnet prop add –version <version>
- command for the property and option for the operation: dotnet prop version –add <version>|—del