-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
MSBuild integration #3
Comments
Hate to say it but I think you need an msbuild task here. https:/natemcmaster/Yarn.MSBuild might be an inspiration |
@adamralph There are two main ways you can integrate the logic into MSBuild:
Option 1 means you have to output all the needed values to the console and them parse them back out in your MSBuild targets, which can be messy. Option 2 still means you could also ship a separate command-line tool if you want (for example as a .NET Core global tool), but the actual logic would be invoked directly as a task, and then you can get all the needed values back as regular properties. Option 2 might seem like the best option, but there is a caveat here as well. Because you're using LibGit2Sharp, getting an MSBuild task working fully cross-platform is non-trivial. There are platform-specific native binaries that you have to deal with. MSBuild offers no assistance in making sure the correct one is loaded, so you have to handle all of that yourself. At the moment, that would involve some level of RID analysis to choose the correct binary. There are LibGit2Sharp changes coming "soon" that will make all of this more palatable, though. Invoking a command-line tool instead could leverage .NET Core's ability to load the correct binary for you, so that's one reason that might be better. This is likely to be slower though, and this something needs to be invoked every time you build. |
I think option 2) is the the most viable. Publish a dotnet cli tool e.g. Also, I don't think slowness is an issue here... normally you would invoke this as part of your CI process, not on your dev machine. |
You seem to be mixing things a bit. Option 1 would be the "invoke a command-line" approach, but you wouldn't really be able to tie that to a .NET Core global tool, since there would be no way to ensure the tool was installed. The link you posted is detailing what I called Option 2, but that doesn't address any of the difficulties around the native libraries.
I disagree. This is something you'll have installed in your project, and it will run as part of your build. |
Sorry if I wasn't more clear. What I am suggesting is that you can slip in an |
I'd like to avoid building an MSBuild task if possible, so right now I'm favouring option 1. I'm hoping it can be as simple as having an executable sitting next to the I've pushed my initial naive attempt to https:/adamralph/min-ver-sandbox. (All the If you run One obvious problem is that Another thing I've observed is, if I set The idea is that MinVer will indeed run on every build, not just on a CI server. I'm hoping performance won't be a problem. |
Are you okay with requiring the .NET Core SDK to be installed? If not, you'll need to ship two different executables and choose which one to run, either .NET Core or .NET Framework.
You'll need to package the
Take a look at https://docs.microsoft.com/en-us/visualstudio/msbuild/exec-task?view=vs-2017. It says both standard error and standard output will be captured.
You'll also want to set You should also change your for BeforeTargets to That ensures the logic is run even with |
Yes, I believe that's an acceptable pre-requisite.
Thanks. FWIW, I switched the sandbox to that output in https:/adamralph/min-ver-sandbox/commit/27df9e8bf4aa6f7ebbff28431ca6bae03326255d
If possible, I'd still like to allow the use of
I was hoping to avoid having to set
Right now I'm hoping to just replace the setting of
Thanks. I've changed it to that in https:/adamralph/min-ver-sandbox/commit/d08d4dbfc7ae2a0e2f8b3283d798137efe8d0567 So I guess the thing I'm still stuck on is working out which MSBuild incantations I need to get the version number out of stdout and into |
Sadly it looks like |
I'm also not sure you'll be able to avoid setting PackageVersion since Version is being calculated. It is set here: https:/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L28 But since that is in a top-level PropertyGroup, that means it's evaluated before you have a chance to set any version values in targets. |
Since MSBuild takes all environment variables and turns them into properties, you could still do this by appending that property when you set Version. |
Aha, that explains it, thanks! Indeed, if I set
I'd like to avoid giving MinVer knowledge of specific CI environments, but I guess this could be done the other way round: MinVer could look for an environment variable named |
Woot! I've got it working, but in a very hacky way. It's using a file to capture stdout: https:/adamralph/min-ver-sandbox/commit/3b38e968e6c2cb049a25625ee0fe2d4eb4418b0d I also threw SourceLink in there just to see how it behaves. Another thing I've realised now is that |
Why is that? When I was testing it earlier, I was able to do that just fine. |
Try loading the assembly into ILSpy. It blows up. 😄 I guess ILSpy is making an assumption about the |
When I do that, everything looks fine. AssemblyVersion is just the numerical portion, as I would expect. |
Yeah, on closer inspection, the ILSpy exception stack trace suggests it might just be some other bug:
How are you seeing |
OK, I just loaded it into So I guess the next step is to find a less hacky way than piping stdout to a file and reading it back in. Also I think this isn't going to work:
I think MinVer will have to look for a specific property as an override, e.g. |
Can you add a commandline parameter to skip all the other output, so you just get the value you need, simplifying the parsing? Otherwise, you'll have to do all of that in the target. |
I'd quite like the ability to have some MinVer log messages in the output, e.g.
But until now, no actual parsing is required. I'm only using the file because I can't isolate stdout in the |
FTR I found the bug in ILSpy. It didn't like when |
@adamralph I do and I will! 😄 |
FWIW I've added a checklist to the description of this issue. |
@adamralph I've opened #53 to set the MSBuildAllProjects property. I also look a look at the design-time build stuff, and it turns out that we need to let this run during design-time builds in order to get project references versioned correctly in the generated nuspec. I'm not entirely sure why that is. It feels like it might be a bug, but I need to do a bit more research before filing an issue about it on NuGet/Home. |
One last thing, are you sure https:/adamralph/min-ver/blob/e2f3f6662918ef5db7a50cc1caa3ae9b94a6f650/MinVer/MinVer.targets#L24 is needed? It seems like that line could be removed and nothing would change. At that point either MinVerVersion has the correct value, or it needs the build metadata appended. It shouldn't need to be set again. |
In the end I decided to spin off the design time build suppression into #55. |
Essentially, making this work: https:/adamralph/min-ver#quick-start
suppress the target for design-time builds- moved to Suppress the MinVer target for design time builds #55The text was updated successfully, but these errors were encountered: