templating
templating copied to clipboard
Create new item templates for Directory.Build.props and Directory.Build.targets
Problem
Closes #5004
Solution
Adds new buildprops and buildtargets templates that scaffold out almost-empty props and targets files. Also includes a parameter to insert an Import of any props/targets in parent folders - since a common pattern with these files is to 'chain' them across directories.
Tasks remaining:
- [ ] Check the VS experience to see what needs to be done about any UI check marks
- [x] Check with @JanKrivanek and @vlada-shubina about the best place to put tests for this.
Checks:
- [x] Added unit tests
- [ ] Added
#nullable enableto all the modified files ?
Thanks @JanKrivanek - made those changes.
I haven't been able to get these to show up in VS's item template list (or tested VSMac yet) despite the info I got from @phenning yesterday, so I'll need to reach out to him to sanity-check myself before we merge this.
@baronfel you could try to add an appliesTo to see if that helps. Some ideas of what you can try include.
.netCPSmanaged
If it works we can figure out what the right capability is to trigger this.
FYI to see the capabilities in a project add the following to the project, and then you will see them in the VS Solution Explorer.
<ItemGroup>
<ProjectCapability Include="DiagnoseCapabilities"/>
</ItemGroup>
Nice @sayedihashimi - adding an appliesTo of Web got me the following on an ASP.NET Core WebAPI project:

Using just Net or .NET (what I saw in the project capabilities list) of a raw console app didn't trigger similarly though, so I have some experimentation to do to figure out what the correct capability should be.
Also, I noticed that the header was "Common Items", not "C#" - do we have control over that? I thought based on the conversation yesterday that the items should appear under "C#".
I thought it would go in the C# node if the language is set correctly. Will need to discuss with Phil.
I thought it would go in the C# node if the language is set correctly. Will need to discuss with Phil.
It should. I just opened a bug to track. Fix incoming for 17.4 Preview 2
@baronfel we should add an icon for these as well. What do you think of the images below (best viewed with light theme, doesn't look good in dark theme). You can just click on the image to see if with a white background.

@sayedihashimi any reason we can't use msbuild.ico from the msbuild repository? https://raw.githubusercontent.com/dotnet/msbuild/e5bc7994348dba88d1f6fe2ebd6aa354355f0063/src/MSBuild/MSBuild.ico
That's the old icon, the updated one is one of those that I attached. If you really want that one, I guess we could buy we'd need to get a .png file instead of .ico.
Ok, I'm down to go with the new one. There was a discussion at the MSBuild repo about updating the icon recently (https://github.com/dotnet/msbuild/discussions/7712), do you know where this new one is stored? It would make sense to me to put it in the repo and use it as the executable's icon if there's something cleaner.
By the way, .ico should work in Visual Studio, we do support both, technically we support ICO + any other bitmap format that can be loaded into BitmapImage.
The icon search order is: ("icon" property path specified in host file), "ide\icon.png", "ide\icon.ico", "icon.png", "icon.ico", (from nupkg)
Alright, just pushed up what might be the last version of this.
I added an icon and verified the display in VS:

One interesting note about the behavior of multiple runs of this item template - VS let me create the item template, but it didn't actually take. It didn't erase modifications I'd made to the file and it didn't create any suffixed versions and add them to the project. So for some reason, out of the box, I have the behavior I wanted anyway! The only thing missing is the ability to specify parameters - the New Item dialog in VS doesn't give me anywhere to specify the Inherit parameter.
Alright, just pushed up what might be the last version of this.
I added an icon and verified the display in VS:
One interesting note about the behavior of multiple runs of this item template - VS let me create the item template, but it didn't actually take. It didn't erase modifications I'd made to the file and it didn't create any suffixed versions and add them to the project. So for some reason, out of the box, I have the behavior I wanted anyway! The only thing missing is the ability to specify parameters - the New Item dialog in VS doesn't give me anywhere to specify the Inherit parameter.
See my message thread with you directly on teams about the silent non-overwrite behavior. I'll copy that information into a mail and we can discuss it with the team.
Unfortunately, new item dialog doesn't have the additional information page/wizard flow like the project dialog does. Best to figure out which default is most common and go with that for now.
Thanks @phenning! I think this is at a state where we could consider merging it, and as the VS-side enhancements become available update these templates. Presumably some of the things we're talking about there for the VS experience would be useful for other single-use-style templates like EditorConfig or GitIgnore?
@baronfel I sent you the link to the website over email where you can find icons.
This should be done in dotnet/sdk repo now.