Sdk: CRUD dotnet commands for MSBuild properties

Created on 13 Jan 2017  路  7Comments  路  Source: dotnet/sdk

Would be nice if dotnet had commands to add/read/change/remove properties in an MSBuild file.

Example:
dotnet prop set VersionSuffix beta
Would update project to include, or would alter its value if it already exists

<PropertyGroup>
   <VersionSuffix>beta</VersionSuffix>
</PropertyGroup>

Example 2:
Reading properties values.

$ dotnet prop get OutputType
Exe

Scenarios:

  • Tools like dotnet-user-secrets may want to read or manipulate a property in the csproj. Example feature on this tool: https://github.com/aspnet/DotNetTools/issues/166
  • Good for automation scripts such as auto-updating versions. Ex: dotnet prop set VersionPrefix 2.0.0
  • Support reading multiple properties at once. This would simplify MSBuild interaction for CLI tools such as 'dotnet-ef' that need multiple properties from a project.

cc @blackdwarf

Most helpful comment

Could we start with "get" and do "set" later?

Almost all CLI tools need to read properties like OutputPath, AssemblyName, TargetFramework, etc. (dotnet-watch, dotnet-ef, dotnet-xunit to name a few)

Only a few of them need to edit a csproj. And there are simple solutions for this. For example, a CLI tool might simply print a message that says "Please add <xml here> to your csproj".

All 7 comments

We won't get to this before RTM but it's something we should look at soon after. @blackdwarf @rainersigwald for their thoughts.

My general feeling is that this is going to be very expensive for the benefit.

Important factors to consider:

  • Identifying location of adding/changing property. Must consider conditions, imports, and evaluation order to be correct. This is done in CPS but it's hard in general.
  • Getting properties can depend on input properties (configuration, TFM, and so on).

This is done in CPS

Could we abstract this into a class library?

I don't think it's currently very well isolated, but there's nothing conceptually stopping such a thing. Just work.

@piotrpMSFT Any plans to get this done in 2.0 timeline?

@muratg we don't have plans for this in the 2.0 timeline. After thinking about it for a while, I'm leaning towards agreeing with @rainersigwald. This command can only support the basic property adding without devolving into a very messy UX. I'm not sure that in those cases, and you can get into those cases pretty fast, you are not better off just cracking open the file and editing it.

Could we start with "get" and do "set" later?

Almost all CLI tools need to read properties like OutputPath, AssemblyName, TargetFramework, etc. (dotnet-watch, dotnet-ef, dotnet-xunit to name a few)

Only a few of them need to edit a csproj. And there are simple solutions for this. For example, a CLI tool might simply print a message that says "Please add <xml here> to your csproj".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moozzyk picture moozzyk  路  3Comments

noelitoa picture noelitoa  路  3Comments

gkhanna79 picture gkhanna79  路  3Comments

billwert picture billwert  路  3Comments

thomaslevesque picture thomaslevesque  路  3Comments