How to install Nuget package on Server without internet connection or local repo? - msbuild

I have a build server that does not have internet access and I want to install this package on it.
I have downloaded nuget.exe and copied it to the server and added it to my PATH and also copied the nuget package above to the server and tried to install with nuget install microsoft.data.tools.msbuild.10.0.61026.nupkg
But the install fails with
Unable to load the service index for source https://api.nuget.org./v3/index.json.
Is there a way to simply install a nupkg file without a repo? The server is Windows Server 2012 R2.

I am assuming you are using NuGet 3 since this used to work in NuGet 2.
Disabling all your online package sources should allow you to install a NuGet package locally.
So you can either change your %APPDATA%\NuGet\NuGet.Config file so it has no package sources. Or you could use the -source parameter, specifying a package source that works offline, when calling install so the online package source is not used.

I was in the wrong folder when I ran the command. I needed to be one folder above and then specify the folder as the source. Worked.
nuget install -source C:\NugetDownloads microsoft.data.tools.msbuild -OutputDirectory E:\Nuget

Related

Can I execute npm install upon the installation of a NuGet package?

I'm creating a NuGet package which contains TypeScript dependencies...node_modules stuff. I don't want to include the node_modules as part of the package, so I'd prefer to execute npm install after the package installation completes. I've installed the package on a test website, and if I manually execute npm install it works.
I can put it in the readme to execute npm install after the package is completed, but I'd prefer to execute it automatically when the install is complete. Is there any way to make that happen?
Historically, we could write an Install.ps1 PowerShell script to invoke certain actions when installing a NuGet package. However, as of NuGet version 3, this feature is no longer supported:
Powershell script support was modified to no longer execute install and uninstall scripts, but init scripts are still executed.
The Init.ps1 script described above allows us to execute actions when a someone installs our package. Although the blog post above suggests that we can still use Init.ps1 scripts in our packages, the lack of recent documentation for this feature and a comment from a NuGet developer seem to indicate that Init.ps1 is also deprecated and that the behavior may not be available in the future. This makes sense if we consider that NuGet also aims to support Mac and Linux for Mono/.NET Core projects, and these systems do not yet include ubiquitous support for PowerShell like Windows (but they may eventually).
For these reasons, I cannot recommend at this time that we automate the package's post-install steps using NuGet's built-in features. The script that runs npm install must also handle challenges on systems where the npm program is missing or not available in the PATH, and some users may not like the idea of the package installing and running arbritrary code. I think it's fair for the project in question to simply instruct the end user in the README to run npm install after installation. Projects with more complex post-installation steps can instruct end users to run a script that executes each step. If you still wish to try using Init.ps1, continue reading:
The current NuGet docs omit information about Init.ps1, but older documentation from 2007 contains this description:
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.ps1script runs again.
...
These files should be located in the tools directory of your package.
So, we can create an Init.ps1 file in the tools/ directory for our package which might look like the following:
param($installPath, $toolsPath, $package, $project)
Set-Location Path\To\Project\With\Node\Dependencies
npm install
...and then generate the NuGet package. The param() statement for the NuGet convention-based scripts provides the following values:
$installPath is the path to your package install
$toolsPath is the path to the tools directory under the package
$package is your package
$project is the project you are installing the application to. Note: This will be null in Init.ps1. It doesn't have a reference to a particular project because it runs at the solution level.
Because this script runs whenever we load a solution, it could slow down Visual Studio. We can add a condition to the script that checks if the packages are installed before running npm. Note that this functionality is restricted to NuGet operations run from Visual Studio or the Package Manager Console and likely will not work using the standalone NuGet CLI program because of the coupling of these scripts to projects and solutions.
Discussion to reintroduce Install.ps1 to NuGet

Organizing "elmah.sqlservercompact" nuget package

I installed both the elmah.mvc and elmah.sqlservercompact (package link) nuget packages. This gets elmah to log to Sql Server Compact.
Problem is it copies a large number of files from the _bin_deployableAssemblies folder, on every build.
How do I change this to deploy/copy only if file has changed, like I can do for other resources?
Seems when I install the SqlServerCe package manually, it doesn't add all those binaries to the build file.

how install glimpse nuget package on IIS server

Package is installed on local machines with a reference to packages folder added in project. Now If I publish it on server, it is causing problem as glimpse is not installed on server. Please guide what is the best way to install it on server.
Glimpse just needs its DLL's to be in the bin folder on the server.
Some deployment techniques (like on Azure Websites) leverage NuGet package restore to download dependencies and build your site right on the server. With these techniques you don't have to do anything.
For simpler techniques, like xcopy or FTP of files, just make sure to include the DLL's - they are already being copied to the bin when you build your site.

Running NuGet in OpenSuse

I am trying to run NuGet.exe (Nuget BootStrapper) in OpenSuse using mono. I am following article mentioned here . But I am facing problem. When I try to run NuGet.exe using mono it gives error that NuGet Package Restore is not enable, please enable it using Visual Studio or set Environment variable. Obviously I don't have Visual Studio in Linux so I am trying to set Environment variable using export. But I am still getting same error.
I am stuck there.
Please let me know if any further information required.
The error you get is because of NuGet Package Restore requiring consent. More information on this package restore consent can be found here: http://blog.nuget.org/20120518/package-restore-and-consent.html
By default, package restore is using the NuGet.exe install command with the -RequireConsent option (command reference). You can find this in the NuGet.targets MSBuild file in the $(SolutionDir).nuget folder (default). Simply remove the -RequireConsent option.
If you are not using the -RequireConsent option, NuGet package restore should not be looking for the environment variable and your issue should no longer exist.

During build/deploy, how do I get around Nuget packages that only copied files?

Background
I have an MVC3 project to which I added the Twitter.Bootstrap.Less Nuget package.
To my knowledge, all this did was copy the appropriate JavaScript / LESS files into their appropriate directories.
However, when I now run this through my build/deploy process onto my dev server, MSBuild doesn't copy the /Content/less folder to my production server as part of deployment package.
My build server doesn't have an internet connection, so unfortunately using NuGet without committing packages to source control isn't an option.
Question
How do I get MSBuild to deploy these files? Or do I need to copy the files, uninstall the nuget package, and manually copy them back in?
You could setup your own internal NuGet package source. That would be internal to your network and mean the build server could pickup the NuGet packages without an internet connection.
E.g. On the server, copy the packages you need to a folder and setup a package feed to that folder for the build server to use.
See:
http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds