Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

How does this work? #2

Closed
ygoe opened this issue Jul 4, 2017 · 3 comments
Closed

How does this work? #2

ygoe opened this issue Jul 4, 2017 · 3 comments

Comments

@ygoe
Copy link

ygoe commented Jul 4, 2017

Not really an issue, more like a question…

I found this repo through your issue NuGet/Home#5063 and closely looked at its project implementation because I'm trying to achieve the same thing: I want to make a NuGet package that installs a custom MSBuild task and always runs it when building the project this package is installed in. But it doesn't do anything.

I created the task project, targeting .NET 4.6 and .NET Standard 1.6, all with VS 2017 update 3 preview 3, and manually set it up in my demo project. The purpose of my task is to determine the software version from Git for example and provide it to the project's Version property. (Others have done similar things before, but for the old MSBuild format, and I have more features to port from an older tool, see ygoe/NetRevisionTool#18.) In my manual setup everything worked. But I needed to do the following things in my demo project:

  • Determine the custom task assembly file name depending on the MSBuild runtime type
  • Register it with <UsingTask>
  • Add a target that runs BeforeTargets="BeforeBuild"
  • Call my custom task in there to have the Version property set

My goal is to move all of this into the NuGet package and it should be active without further configuration. (It will have configuration, but for other things like the version string format.)

I guess after installing that package there should be some visible references in my demo project (.csproj file, targeting .NET Standard 2.0 for now) but I can't find any, and I also can't find the location that the package has been installed to. No "tools" directory anywhere and also no "*.targets" file. Is there some magic spell I need to add to it?

Maybe you'd like to write a comprehensive blog post about making MSBuild task NuGet packages. :-)

@natemcmaster
Copy link
Owner

@ygoe there are a lot of things required to make an MSBuild task cross-plat. You can poke around this code, but it may be hard to find the key ingredients. I think you're right - a blog post is probably the best format for a response. I'll cook something up and post here when it's available.

@ygoe
Copy link
Author

ygoe commented Jul 5, 2017

That would be awesome, thanks for your effort!

@natemcmaster
Copy link
Owner

Let me know you still have unanswered questions:

http://www.natemcmaster.com/blog/2017/07/05/msbuild-task-in-nuget/

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

No branches or pull requests

2 participants