Itiviti / gradle-nuget-plugin

Executes NuGet from a gradle build
Apache License 2.0
22 stars 29 forks source link

RE: override property for the msbuildversion. #56

Closed JamesPoli closed 6 years ago

JamesPoli commented 6 years ago

Hello, We need an override property for the msbuildversion on the Nuget pack and restore. Any possibility of getting it added? Thanks, Jim

gluck commented 6 years ago

Hi James, What do you mean by that ? NugetPack doesn't make use or rely on Msbuild (but if gradle-msbuild plugin is applied and used, it gets its default values from the gradle-msbuild setup)

Thx

JamesPoli commented 6 years ago

Francois,

First, thanks for looking at this.

From what I can tell, inferring output in a debug log, that both nuget pack and restorehttps://docs.microsoft.com/en-us/nuget/tools/cli-ref-restore use msbuild (perhaps to obtain property values from Visual Studio metadata files?).

++ LOG OUTPUT BELOW ++ ... 09:59:05.007 [QUIET] [system.out] NuGet Version: 4.3.0.4 09:59:05.008 [QUIET] [system.out] Restoring NuGet packages for solution C:\Users\japoli\WinCDP\CDPINT-3551\ConsoleApplication\ConsoleApplication.sln. 09:59:05.068 [QUIET] [system.out] MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.

Both commands have a msbuildversion option otherwise nuget will use its own algorithm to determine the which one to use (latest installed).

I'm running into a problem when I run the nuget plugin for a restore where nuget chooses an incorrect version of msbuild (15.0) for my project which used msbuild version 12.0 in Visual Studio when I created it. FWIW, I have several versions of Visual Studio installed on my machine.

++ LOG OUTPUT BELOW ++ ... 09:59:05.206 [QUIET] [system.out] C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\msbuild.exe /t:GenerateRestoreGraphFile /nologo /nr:false /p:RestoreUseCustomAfterTargets=true /p:BuildProjectReferences=false /v:q /p:NuGetRestoreTargets="C:\Users\japoli\AppData\Local\Temp\NuGet-Scratch\wexslzjz.d0q.targets" /p:RestoreTaskAssemblyFile="C:\NuGet\NuGet.exe" /p:RestoreGraphOutputPath="C:\Users\japoli\AppData\Local\Temp\NuGet-Scratch\ut1rhbt3.a0k.result" /p:ExcludeRestorePackageImports=true /p:RestoreSolutionDirectory="C:\Users\japoli\WinCDP\CDPINT-3551\ConsoleApplication" /p:RestoreRecursive=False /p:RestoreProjectFilterMode=exclusionlist /p:RestoreContinueOnError=WarnAndContinue /p:RestoreGraphProjectInput="C:\Users\japoli\WinCDP\CDPINT-3551\ConsoleApplication\ConsoleApplication\ConsoleApplication.vcxproj;" "C:\Users\japoli\AppData\Local\Temp\NuGet-Scratch\wexslzjz.d0q.targets" 09:59:05.452 [QUIET] [system.out] NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.

I do use the gradle-msbuild plugin, perhaps the nuget exec for restore/pack could use it’s default value as part of the msbuildversion option?

Thanks, Jim

From: Francois Valdy [mailto:notifications@github.com] Sent: Tuesday, November 07, 2017 5:33 AM To: Ullink/gradle-nuget-plugin gradle-nuget-plugin@noreply.github.com Cc: James Poli James.Poli@sas.com; Author author@noreply.github.com Subject: Re: [Ullink/gradle-nuget-plugin] RE: override property for the msbuildversion. (#56)

EXTERNAL

Hi James, What do you mean by that ? NugetPackhttps://github.com/Ullink/gradle-nuget-plugin/blob/master/src/main/groovy/com/ullink/NuGetPack.groovy doesn't make use or rely on Msbuild (but if gradle-msbuild plugin is applied and used, it gets its default values from the gradle-msbuild setup)

Thx

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Ullink/gradle-nuget-plugin/issues/56#issuecomment-342441221, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFbDPse8wowsJPyzXrC1xnCzNCeEuAIuks5s0DHIgaJpZM4QTK8P.

gluck commented 6 years ago

Your proposal sounds about right, we could add the MSBuildVersion param (to all nuget tasks or only some of them ?), and add a default mapping to the one used by gradle-msbuild.

Interested in picking up the task ? I myself have never had the need for this param, and the only related link I found doesn't make it clear what value this parameter takes.

Thx.

JamesPoli commented 6 years ago

Sure, I'll try to implement the task; that way I can test it. I'll review the command's again but I believe only the pack and restore support the msbuildversion. Ah, I found that update also supports the option. Regards, Jim

JamesPoli commented 6 years ago

Francois, I've started work on this effort. FWIW, to test, I made several changes to the NuGetRestore task for a new msBuildVersion property. But, alas, defaulting the msBuildVersion to the MsBuild's version property doesn't appear to be working.? In the task graph, the NuGetRestore task is running before the MsBuild task, thus the msBuildVersion property is always null. Perhaps, my idea wasn't so great after all? Possibly, I need some special Gradle magic to get this working? Anyway, since my plugin simply wraps your Nuget and MsBuild tasks, I was able to set the NuGetRestore msBuildVersion property in a private task beforehand, thus getting the behavior I needed. I'll finish NuGetPack. Since you don't have a NuGetUpdate task I won't worry about that. I'll continue to code and test, then push and do a pull request. Let me know if that sounds alright. Regards, Jim

gluck commented 6 years ago

The task graph shouldn't matter, if version was set on msbuild task, you can use it right away.

Note that if it wasn't set explicitely in the gradle build, then it'll resolve to the latest when executing the msbuild task, in that case you can't get the version used, but you shouldn't need to (if msbuild is set to using the latest, nuget should do the same, meaning the version shouldn't be set explicitly).

Feel free to push your changes as a PR even if not finished yet, we can discuss on that.

JamesPoli commented 6 years ago

Looking closer at our code, we set the version at runtime prior to the msbuild task running which matches your explanation, thanks. I'll go ahead and add back in the code that uses the msbuild version if it's set. I've got some more testing to do, then I'll push. How do you want me to push? In a separate branch or in a fork?

JamesPoli commented 6 years ago

Sorry, Francois, it's taking a while, the code is complete; I'm just waiting for legal approval from SAS to commit it. Should be approved this week. Jim

JamesPoli commented 6 years ago

Ok Francois, created PR. Jim

JamesPoli commented 6 years ago

What's the process to get this released?

ngyukman commented 6 years ago

released in 2.16