Nuget creating a folder with the package name - nuget

I created a nuget package "MyClassLib.1.0.0.nupkg" and I am looking to install it in under ClassLib folder of my solution.
However when I install the package it install as below
SolutionFolder\ClassLib\MyClassLib.1.0.0\MyLibraries
Excepted :
SolutionFolder\ClassLib\MyLibraries
How can I prevent the folder MyClassLib.1.0.0 from being created.
Note - I use Nuget Package Manager 2.8.6

The folder structure issue was not the real problem, placing the dlls in the respective folder was the original issue. The below solution may help any newbies.
Writing a power shell script Copy-Item $src $dest -recurse -force inside the install.ps1 copied the contents of the packages into the required folder solved the problem.
Nuget package needs to have a folder named tools and a script file "install.ps1" which is automatically executed everytime the nuget package installation happens.

Related

nuget install does not actually install the software?

I created one internal nuget repository and stored 7zip nuget package in it.
Added internal repo using , nuget sources Add -Name "localnuget" -Source http://10.xxx.xx.xxx:xxxx/repository/nuget-hosted/
But when i used nuget install 7Zip.sfx -Source localnuget it is just extracting it and putting it inside a folder in which i can see tools folder which contains the 7Zip exe file.
nuget cli will install this exe file or not?
NuGet.exe will not install software contained in NuGet packages. It will extract the contents of the NuGet package to a local folder.
tIf you are looking to install 7zip you should use one of the following:
The official 7zip installer.
Chocolately - if you want a command line package manager.

NuGet: Update a package to a specific version in all projects via PowerShell or CMD

We have a scenario, where different teams work on different parts of a larger product. From time to time, all Visual Studio Projects of all Solutions there need to get some of their referenced NuGet packages updated. As a result of that update, all projects in the whole source tree should reference the same versions of the packages.
Is there a way to update a specific NuGet package to a specific version in all projects using some automatic approach like PowerShell scripts?
Edit:
Is there a way to somehow load the necessary parts of Visual Studio and NuGet to also update the assembly references correctly?
Example:
NuGetScript Update Solution.sln PackageName -version NewVersion
or
NuGetScript Update PathToProjects PackageName -version NewVersion
There are too many components to load all of them in Visual Studio and update them manually via package manager UI.
Please use following command line in Package Manager Console window to update a specific package in one solution.
Get-Project -All | Update-Package PackageName -Version newVersion
You can create a PowerShell script to search all the project files or packages.config files in your solution and then call nuget update command to update the packages.
However, there is a limitation when update packages outside of Visual Studio, I would recommend you to do this from Visual Studio:
The update command will download and extract all new packages to the
packages folders. Assembly references will be updated in the project
file, however this is limited to only existing references. If a new
package has an added assembly it will not be added as part of the
update command. New package dependencies will also not have their
assembly references added. To perform a complete update use Visual
Studio.
The following script was found somewhere else. I have tried it with my projects. I don't have the original link
The following script does:
run restore command on any solutions found within a folder
Finds all packages.config files containing the package id name provided
runs update command using the packages.config file and the package name as parameters
This assumes that nuget.exe is present in the folder where you will be running this from
param(
[Parameter(Mandatory=$true)]
[string]$packageId
)
Get-ChildItem *.sln -recurse | %{.\\nuget.exe restore $_.fullname}
Get-ChildItem packages.config -Recurse `
| Where-Object {$_ | Select-String -Pattern $packageId} `
| %{.\\nuget.exe update -Id $packageId $_.FullName}

Restoring NuGet packages

I have a C# solution containing several projects. Some of projects has referenced nuget packages. Whole solution (but no downloaded dlls) is tracked by git repository.
After cloning it to other place and trying to build nuget asks if it should download missing packages. After downloading there are still several referenced library missing.
I can fix it one by one doing following steps:
Remove reference
Remove package in packages.config file
Install this package again by nuget
Is there any better way to do this? I tried reinstalling all nuget packages, but my Visual Studion crashes. After restarting and retrying it left me with more missing packages.
Another way to do this is running:
PM> Uninstall-Package {Name}
PM> Install-Package {Name}
for each missing package. By missing package I mean all packages with yellow mark. I can't install it without uninstall command, becasue nuget says it is already referenced.
If you try running the following from the command line does it restore all the packages?
nuget.exe restore YourSolution.sln
If not then it sounds like there's some packages that are missing from your project's packages.config file.
You could try the updating the packages with the reinstall parameter from the PowerShell console.
Update-Package –reinstall <packageName>
You can also restrict this to one project if you want to by using the -ProjectName parameter.
This is probably because of the incorrect path of the .dll in your .csproj. The package restore downloads the packages to the local directory.
It doesn't change the reference path of the assembly in the .csproj, meaning that the project will still try to locate dlls on the local directory. The yellow mark means the project is unable to locate the assembly.
Unload the project, right click on project and select "Edit .csproj", and verify the path of missing dlls.
For example - If you have NUnit,
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
verify if the dll is present inside "\packages\NUnit.3.6.1\lib\net45" directory.

What is the recommended way to copy a .NET exe and its DLLs with a NuGet package

I am creating a NuGet package, which is a library DLL. I did this successfully.
However I would like to have a .NET exe (and its dependent assemblies) also in the target machine. It is completely OK if the .exe and these dlls are under the solution's package folder.
If it is possible I do not want to create a standard Windows installer and run it silently.
Thanks in advance
You'll have to edit your .nuspec file. You can include a element to include additional files in your package. Look at what else you can do by looking at the specs.
You can run your exe by creating a powershell script during package installation.
Starting from NuGet 2.0 a package can contain a "tools" folder. Here you can put exe, scripts and so on.
http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Framework_Version_Folder_Structure
Binary under this folder will not be referenced, just copied on the machine.
Hope it helps.

NuGet how to apply properties to files

I am creating NuGet Package. I have put two files in content folder, exe and config files that will be added when user installs this package.
In addition I would like to change VS project properties for these two files.
What do I need to do for that when building the package?
When you say "apply properties change" do you mean file system properties such last modified time, hidden flag, etc.?
If so there are a set of PowerShell scripts that are run (if they exist in your package) you can use to do this. It won't happen when you build the package, but it will run when somebody installs the package - which should have the same effect form the users point of view. You probably want either Init.ps1 or Install.ps1.
From Automatically Running PowerShell Scripts During Package Installation and Removal in the NuGet docs:
A package can include PowerShell scripts that automatically run when
the package is installed or removed. NuGet automatically runs scripts
based on their file names using the following conventions:
Init.ps1 runs the first time a package is installed in a solution.
If the same package is installed into additional
projects in the solution, the script is not run during those
installations.
The script also runs every time the solution is
opened. For example, if you install a package, close Visual Studio,
and then start Visual Studio and open the solution, the Init.ps1
script runs again.
Install.ps1 runs when a package is installed in a project.
If the same package is installed in multiple projects in a solution,
the script runs each time the package is installed.
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.
If your package also has an init.ps1, install.ps1 runs after init.ps1.
Uninstall.ps1 runs every time a package is uninstalled.
These files should be located in the tools directory of your package.
At the top of your file, add this line: param($installPath, $toolsPath, $package, $project)
$installPath is the path to the
folder where the package is installed
$toolsPath is the path to
the tools directory in the folder where the package is installed
$package is a reference to the package object.
$project is a
reference to the EnvDTE project object and represents the project the
package is installed into. Note: This will be null in Init.ps1. In
that case doesn't have a reference to a particular project because it
runs at the solution level. The properties of this object are defined
in the MSDN documentation.
When you are testing $project in the console while creating your scripts, you can set it to $project = Get-Project