Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing SDK style builds #3410

Closed
MarkPflug opened this issue Jun 13, 2018 · 7 comments
Closed

Customizing SDK style builds #3410

MarkPflug opened this issue Jun 13, 2018 · 7 comments
Labels

Comments

@MarkPflug
Copy link

I have a question regarding customizing SDK style projects. In old-style projects, I could redefine any standard Target that I wanted, by placing my own definition after the Import for "Microsoft.CSharp.targets". However, with the new SDK style projects the SDK.targets is implicitly added to the very end of my project file, so there is no "after" for me to include my redefinitions. Is there a way to do this with SDK style projects, or is this simply no longer an option?

@MarkPflug
Copy link
Author

MarkPflug commented Jun 13, 2018

Okay, I think I figured it out. It seems that all that Sdk="Microsoft.NET.Sdk" is doing for me is adding those Imports, so I can just replace that with an explicit import instead:

<Project>
<Import Sdk="Microsoft.Net.Sdk" Project="Sdk.props"/>

... my project stuff ...

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets"/>

... override targets here ...

</Project>

I only realized this after I saw that the Import element now has an "Sdk" attribute (thanks Intellisense).

Is this really all the Sdk attribute on Project is doing?

@eerhardt
Copy link
Member

Is this really all the Sdk attribute on Project is doing?

Yes, that's all that attribute does - automatically adding the Imports at the top and bottom of the project. See #1493 and #1392.

@dsplaisted
Copy link
Member

@MarkPflug If you want your override targets to apply to more than just one project, you may want to put them in a Directory.Build.targets file in the root of your repo. It will automatically be imported after the common targets, and you don't have to change your projects to use explicit SDK imports. See Customize your build for more information.

@eerhardt
Copy link
Member

@dsplaisted - unfortunately, Directory.Build.targets doesn't work as great as Directory.Build.props. The props file does get imported rather early, so you can set a bunch of things before the SDK's props file.

However, the Directory.Build.targets file gets imported towards the end of Microsoft.Common.targets:
https://github.com/Microsoft/msbuild/blob/cb6c2643fe4a072f28e685bc46df3bace17a7108/src/Tasks/Microsoft.Common.targets#L147

And from there, most of the Microsoft.NET.Sdk's .targets files get imported after Microsoft.Common.targets, and thus after any Directory.Build.targets.

So if you want to override things after a SDK's .targets files, your only real option is to explicitly import the SDK.targets file. 😞

@MarkPflug
Copy link
Author

Thanks for the suggestions guys. I've got things working acceptably well now. One thing I'd suggest for documentation improvement, add a link from What's New In MSBuild 15.0 directly to How to: Use MSBuild Project SDKs.

That SDK topic is under "MSBuild Targets", which I didn't bother exploring, because I (thought I) knew all about how targets work. Honestly, the SDK feature feels like it should be its own top-level topic.

@rainersigwald
Copy link
Member

@Mikejo5000 Feedback on doc organization ☝. Thoughts on making those changes? I'm not sure SDKs deserves a top-level feature, but user feedback is important.

@Mikejo5000
Copy link

@rainersigwald I'll add the link from What's New. Bumping up the topic to a higher TOC level seems like it would require the addition of a new TOC node such as "MSBuild Projects", but then we'd need to add new content on projects to make sense of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants