Itiviti/gradle-nuget-plugin

Can nugetPack / nugetPush work off the csproj?

Closed this issue · 6 comments

nugetPack "Creates a NuGet package based on the specified nuspec or project file."
My nugetSpec is using the spec file... but the spec file is just a template with $id$ $version$, etc. being populated by the project.
Is there a way to specify nugetPack pass the project file in instead of the spec file?
nugetSpec {
nuspecFile = file("${project.name}.nuspec")
}

Looking at the source, it looks like I can specify a csprojPath file. But again, it is unsuccessful.
For the version and metadata, the plugin prefers the spec file over the project and the project over the csproj. But again, my nuspec just has $version$ for a version. It is filled in by the project. Even if I manually set and overwrte this as the callfire-api-client-csharp project did, it seems to be looking for all the toher metadata attributes in the nuspe - all of which are templated $x$

Instead of using the version of the project or the version of the
nugetPack{ csprojPath = file("${project.name}.csproj") }

gluck commented

I struggle to understand what you're trying to do sorry.
Maybe you can try running gradle with -i/--info so you'll see which nuget command-line is being executed for pack, and let us know what you'd like instead, maybe that'll be clearer ?

Good luck.

How is the spec data filled in by the project? Do you have a runtime .targets file which does the logic? I'm pretty sure this will generate a temporary/intermediate .nuspec, otherwise you'll never be able to generate the final .nupkg if there's not real data in the .nuspec, no? What I mean is, AFAIK nuget doesn't combine info from the .csproj to interpolate the values you mention in the .nuspec.

I THOUGHT that is exactly what it was doing - nuget was having the project
fill the spec fields $id$ $title$ $description$ $version$ $author$... or
possibly not using the spec at all and just using the projects attributes.
Not sure. I have very little experience in the non-java domain, I was
sort of thrown into this task. What I do know is I cannot use the plugin
to pack or push, but I can call nuget directly passing in the project file
and it will pack and push. (having to do an extra back flip to get the
version from the AssemblyInfo.cs)
ext['nugetExecutable'] =
"${project.gradle.gradleUserHomeDir}/caches/nuget/${project.extensions.nuget.version}/NuGet.exe"
project.version = getVersion()
ext['nugetPackage'] = "${nugetOutputDir}/${project.name
}.${project.version}.nupkg"
task pack(type:Exec, dependsOn: ['msbuild', 'copyRelease', 'prepack']) {
workingDir "${projectDir}"
executable = "${nugetExecutable}"
args = [
"pack",
"${projectDir}/${project.name}.csproj",
"-OutputDirectory", "${nugetOutputDir}",
"-NonInteractive",
"-Verbosity", "normal"
]
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
task push(type:Exec, dependsOn:'pack') {
workingDir "${projectDir}"
executable = "${nugetExecutable}"
args = [
"push", "${nugetPackage}",
"-Source", "${ARTIFACTORY_PUBLISHING_REPO}",
"-ApiKey", 'ArtifactorySnapshot',
"-ConfigFile", "${projectDir}/../../NuGet.Config",
"-NonInteractive",
"-Verbosity", "normal"
]
}
def getVersion() {
def ver = ''
def regex = ~/[assembly: AssemblyVersion("(.*)")]/
def matcher = regex.matcher(new File(project.assemblyInfo).text)
while(matcher.find()) {
ver = matcher.group(1)
}
project.version = ver
return ver
}
If nuget can do it, it would be nice if the plugin could as well.

Not exactly sure, but looking at the code it would seem it might if it
didn't pass the -Version when passed a csproj instead of a spec and if it
didn't try to check the spec meta data version first when a csproj file was
passed and recognize a spec file was not supplied.
Thinking about it, not sure why you would want to pass a version to nuget
anyway if the version is already either in the spec or in the csproj?
Help says -Version will override the nuspec version, which doesn't seem
like a good idea unless its being done for build automation. But it
basically negates having an AssemblyInfo->AssemblyVersion AND negates
having the spec file version. Possibly nice if someone really wanted that
behavior, but not in the general case.

On Wed, Oct 26, 2016 at 5:27 AM, Timotei Dolean notifications@github.com
wrote:

How is the spec data filled in by the project? Do you have a runtime
.targets file which does the logic? I'm pretty sure this will generate a
temporary/intermediate .nuspec, otherwise you'll never be able to generate
the final .nupkg if there's not real data in the .nuspec, no? What I mean
is, AFAIK nuget doesn't combine info from the .csproj to interpolate the
values you mention in the .nuspec.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#51 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AIaeHtOJ90MrewiFgG_XYi-hMAd8td8Pks5q3x0MgaJpZM4KgSkX
.

FYI: confirmed the spec meta data is being populated from the AssemblyInfo.cs attributes.

nuspec data can be defined in build.gradle already