how to create nuspec file in specific folder? - nuget

I tried to create .nuspec file in a different folder by giving path but
it is giving me error
Nuget.exe spec ..\MYDEMOFOLDER
Nuget.exe pack ..\MYDEMOFOLDER\MYPROJECT.csproj
pause
want to create MYPROJECT.nuspec in ..\MYDEMOFOLDER folder location
getting error to create nuspec file
The package ID '..\MYDEMOFOLDER' contains invalid characters. Examples of valid package IDs in
clude 'MyPackage' and 'MyPackage.Sample'.

Unfortunately nuget.exe spec doesn't work like that. It expects a package ID.
If you need to create a nuspec in a given folder, you will need to change to that directory.
pushd ..\MYDEMOFOLDER // switch to new directory (remember current)
nuget spec MYPROJECT // create MYPROJECT.nuspec file
nuget pack MYPROJECT.csproj // pack MYPROJECT.csproj
popd // return to previous directory
NOTE: If you're going to pack a project file, you don't need to create a nuspec file, as nuget will create one automatically.

navigate to the directory you want to create the file
download this nuget exe in the directory
cd to the directory on command line
use the command "nuget spec project.csproj"
check your directory for the generated nuspec file

Generate .nupkg file using below command
nuget pack MYPROJECT.csproj
change the .nupkg file extension to .zip.
Open the zip you will see the .nuspec file.

Dotnet has quite confusing similar arguments
--output
is used for output for build = input for nuget pack
/p:OutputPath=
is used as output folder of nuget pack itself
Example:
dotnet pack -c Release -p:PackageVersion=1.2.3 YourProject.csproj --no-build --output c:\outputofbuild /p:OutputPath=c:\outputfornuget

Related

nuget tfs build 2015

I am trying to use NuGet to package and publish the package with TFS Build 2015 to local NuGet Server. I am getting error , I am not sure what am i missing. Thanks for Help.
Here is Error
Starting task: NuGet Packager
Set workingFolder to default: C:\Lucky\agent\tasks\NuGetPackager\0.1.58
Executing the powershell script: C:\Lucky\agent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
Checking pattern is specified
No Pattern found in solution parameter.
Found files: 1
--File: "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter"
The property DirectoryName does not exist or was not found.
Creating Nuget Arguments:
--ARGS: pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release
Invoking nuget with pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release on
C:\Lucky\agent\agent\worker\tools\NuGet.exe pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Please specify a nuspec or project file to use.
Unexpected exit code 1 returned from tool NuGet.exe
Finishing task: NuGetPackager
Task NuGetPackager failed. This caused the job to fail. Look at the logs for the task for more details.
According to the error info:
Please specify a nuspec or project file to use. Unexpected exit code 1
returned from tool NuGet.exe
You may specified a wrong argument in nuget package task ,please double check you have followed below requirements:
Specify .csproj files (for example, **\*.csproj) for simple projects. In this case:
The packager compiles the .csproj files for packaging.
You must specify Configuration to Package (see below).
You do not have to check in a .nuspec file. If you do check one in, the packager honors its settings and replaces tokens such as $id$ and
$description$.
Specify .nuspec files (for example, **\*.nuspec) for more complex projects, such as multi-platform scenarios in which you need to
compile and package in separate steps. In this case:
The packager does not compile the .csproj files for packaging.
Each project is packaged only if it has a .nuspec file checked in.
The packager does not replace tokens in the .nuspec file (except the element, see Use build number to version package,
below). You must supply values for elements such as and
. The most common way to do this is to hardcode the
values in the .nuspec file.
Please double check your arguments , more details please refer this tutorial-- Pack NuGet packages.
Besides you could also enable verbose debug mode by adding system.debug=true to get a more detail build log info for troubleshooting.

VSO using Nuget packager build agent fails with invalid properites

I'm using VSO to package a simple DLL and the publish it to an internal feed, unfortunately during the packaging stage build it reports success but I get no artifact to publish
In the log file on for the publish it states the packing includes invalid arguments (Log 2016-02-27T09:07:35.8808468Z) as a result the publisher can't file any .nupkg file to publish.
I'm not sure where I'm going wrong. Its as if the nuget.exe is the wrong version or do it need to include anything in my solution
this is just a basic .enter image description herecsproj library with one static function for testing the process.
packager log
2016-02-27T09:07:35.2714664Z Set workingFolder to default: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\NuGetPackager\0.1.57
2016-02-27T09:07:35.2714664Z Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\NuGetPackager\0.1.57\NuGetPackager.ps1
2016-02-27T09:07:35.4277177Z Checking pattern is specified
2016-02-27T09:07:35.4433431Z No Pattern found in solution parameter.
2016-02-27T09:07:35.4433431Z Found files: 1
2016-02-27T09:07:35.4589718Z --File: "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj"
2016-02-27T09:07:35.4589718Z Creating Nuget Arguments:
2016-02-27T09:07:35.4589718Z --ARGS: pack "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj" -OutputDirectory "C:\a\1\a" -Properties Configuration=${BuildConfiguration};Platform any cpu
2016-02-27T09:07:35.4589718Z Invoking nuget with pack "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj" -OutputDirectory "C:\a\1\a" -Properties Configuration=${BuildConfiguration};Platform any cpu on C:\a\1\s\NugetTestLibrary
2016-02-27T09:07:35.4747124Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\agent\worker\tools\NuGet.exe pack "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj" -OutputDirectory "C:\a\1\a" -Properties Configuration=${BuildConfiguration};Platform any cpu
2016-02-27T09:07:35.8808468Z pack: invalid arguments.
2016-02-27T09:07:35.8964722Z usage: nuget pack <nuspec | project> [options]
2016-02-27T09:07:35.8964722Z Creates a NuGet package based on the specified nuspec or project file.
2016-02-27T09:07:35.8964722Z Specify the location of the nuspec or project file to create a package.
2016-02-27T09:07:35.8964722Z options:
2016-02-27T09:07:35.8964722Z -OutputDirectory Specifies the directory for the created NuGet package file. If not specified, uses the current directory.
2016-02-27T09:07:35.8964722Z -BasePath The base path of the files defined in the nuspec file.
2016-02-27T09:07:35.8964722Z -Verbose Shows verbose output for package building.
2016-02-27T09:07:35.8964722Z -Version Overrides the version number from the nuspec file.
2016-02-27T09:07:35.9120964Z -Exclude + Specifies one or more wildcard patterns to exclude when creating a package.
2016-02-27T09:07:35.9120964Z -Symbols Determines if a package containing sources and symbols should be created. When specified with a nuspec, creates a regular NuGet package file and the corresponding symbols package.
2016-02-27T09:07:35.9120964Z -Tool Determines if the output files of the project should be in the tool folder.
2016-02-27T09:07:35.9120964Z -Build Determines if the project should be built before building the package.
2016-02-27T09:07:35.9120964Z -NoDefaultExcludes Prevent default exclusion of NuGet package files and files and folders starting with a dot e.g. .svn.
2016-02-27T09:07:35.9120964Z -NoPackageAnalysis Specify if the command should not run package analysis after building the package.
2016-02-27T09:07:35.9120964Z -ExcludeEmptyDirectories Prevent inclusion of empty directories when building the package.
2016-02-27T09:07:35.9120964Z -IncludeReferencedProjects Include referenced projects either as dependencies or as part of the package.
2016-02-27T09:07:35.9120964Z -Properties + Provides the ability to specify a semicolon ";" delimited list of properties when creating a package.
2016-02-27T09:07:35.9120964Z -MinClientVersion Set the minClientVersion attribute for the created package.
2016-02-27T09:07:35.9120964Z -MSBuildVersion Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.
2016-02-27T09:07:35.9120964Z -Help (?) help
2016-02-27T09:07:35.9120964Z -Verbosity Display this amount of details in the output: normal, quiet, detailed.
2016-02-27T09:07:35.9120964Z -NonInteractive Do not prompt for user input or confirmations.
2016-02-27T09:07:35.9120964Z For more information, visit http://docs.nuget.org/docs/reference/command-line-reference
Unfortunately I copied the Configuration=${BuildConfiguration} parameter incorrectly (use {} instead of ()), I also had to make other changes , I didn't require the platform parameter. I was also packaging to the incorrect folder.

Nuget pack csproj with dependencies on other csproj

I have two projects
A.csproj
B.csproj
where B references A (reference to project in solution)
I want to automate creation of packages, where package B will contain dependecy to package A
I've generated nuspec using nuget spec A.csproj and created package using nuget pack A.csproj. The same for project B.
however B.nuspec does not contain dependecy to nuget package A?
I want to automate creation of nuget packages on TFS build server, where assembly version is determined at build time.
In package B, how to add dependency to package A with correct version?
Firstly, to add the referenced projects as part of the package, you need to use the IncludeReferencedProjects option.
The command line is something like "nuget pack A.csproj -IncludeReferencedProjects"
Secondly, as you want to create NuGet packages during TFS build process, you need to create one PowerShell script which is similar to the followings, and include the PowerShell script in the Pre-build script (Assume you're using TFS2013 or TFS2015).
$projectFile = "project.csproj"
$nugetPath = “NuGet.exe"
$version = $Env:TF_BUILD_BUILDNUMBER
Write-Host ("packing $projectFile...")
& $nugetPath pack "$projectFile" -Version $version -Symbols -IncludeReferencedProjects

nuspec file inside nupkg

I'm having problems with a custom .nupkg file I have created as the .nuspec file is being added to the package itself. The .nuspec file is held directly under the \src directory and I am using the following command to create the package:
nuget pack .\src\package.nuspec -Version 1.0.0.0 -OutputDirectory C:\Packages\
I am packing directly against the .nuspec file since my solution contains multiple projects each targeting a different .Net version.
Inside the package file, the two files at the root are the "[Content Types].xml" and the .nuspec file (besides the "_relS", "lib" and "package" directories).
For reference I have not yet posted the package and have just a local repository directory.
You need to put the nuspec file outside the src folder
baseFolder
|- src
|- [contents]
|- [contents]
|- package.nuspec
Now, run the command in baseFolder
nuget pack package.nuspec -Version 1.0.0.0 -OutputDirectory C:\Packages\

NuGet - install.ps1 does not get called

I'm trying to create my first NuGet package. I don't know why my install.ps1 script does not get called. This is directory structure
--Package
|
- MyPackage.nuspec
- tools
|
- Install.ps1
- some_xml_file
I build package using this command line
nuget.exe pack MyPackage.nuspec
When I Install-Package from VS Package Manager Console install.ps1 does not get called.
I thought that maybe I had some errors in script and that's the reason so I commented out everything but
param($installPath, $toolsPath, $package, $project)
"ECHO"
But I don't see ECHO appearing in Package Manager Console. What can be wrong?
Install.ps will only be invoked if there is something in the \lib and/or \content folder, not for a "tools only" package, though. See here:
The package must have files in the content or lib folder for Install.ps1 to run. Just having something in the tools folder will not kick this off.
Use the Init.ps1 instead (however, this will be executed every time the solution is opened).
Install.ps1 (and Uninstall.ps1) are no longer called in v3, but you can use Init.ps1. See here:
Powershell script support was modified to no longer execute install
and uninstall scripts, but init scripts are still executed. Some of
the reasoning for this is the inability to determine which package
scripts need to be run when not all packages are directly referenced
by a project.
An alternative to the install script can sometimes be a package targets file. This targets file is automatically weaved into the project file (csproj, ...) and gets called with a build.
To allow Nuget to find this targets file and to weave it in, these two things are mandatory:
the name of the targets file must be <package-name>.targets
it must be saved in the folder build at the top level of the package
If you like to copy something to the output folder (e.g. some additional binaries, like native DLLs) you can put these binaries into the package under folder binaries and use this fragment in the targets file for the copying:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyBinaries" BeforeTargets="BeforeBuild">
<CreateItem Include="$(MSBuildThisFileDirectory)..\binaries\**\*.*">
<Output TaskParameter="Include" ItemName="PackageBinaries" />
</CreateItem>
<Copy SourceFiles="#(PackageBinaries)"
DestinationFolder="$(OutputPath)\%(RecursiveDir)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true"
/>
</Target>
</Project>