Unable to uninstall a NuGet Package - c#

When I'm trying to uninstall a NuGet package using NuGet Package Manager's graphical interface, I'm getting this error :
Object reference not set to an instance of an object.
I have tried many things in Package Manager Console, such as :
Uninstall-Package AutoMapper
or
Uninstall-Package AutoMapper -Force
I'm still getting the same error.
When I'm trying to update a package using this :
Update-Package AutoMapper
I get this :
Update-Package : An error occurred while retrieving package metadata
for 'System.ComponentModel.Annotations.4.3.0' from source
'D:\folder\project\project\packages'.
Can you tell me how I can uninstall a package or make a modification on it? Thanks.
EDIT :
When I try to install Nuget Commandline like this :
Install-Package NuGet.CommandLine
I get this :
An error occurred while retrieving package metadata for
'AutoMapper.5.2.0' from source 'D:\folder\project\project\packages'.

If you can't uninstall your nuget via package manager console or with Nuget Package Manager, you still have the option to go to your project. Open your package.config file.
Looks like this
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net452" />
<package id="bootstrap" version="3.3.2" targetFramework="net452" />
...
There you will find the id of your AutoMapper dependency with the version associated. Remove that line. Open your Nuget Package Manager again, and Install from there if you want to reinstall the package. If you want to remove it completely, then just update the package.config as I explained and you can also remove the folder of AutoMapper on your packages folder, but the later is not necessary, unless you don't wont to keep the package for a future use. Just removing the entry of the Id on your config files will work.

When I upgraded NuGet, the problem solved.

Related

Created nuget package's dll can not be accessable from package's loaded project

I want to create a nuget package of my .net core class library.
I copied the nuget.exe file to the root folder of my Solution
Run nuget spec and Solution.nuspec file created. I modified it as below:
<?xml version="1.0"?>
<package >
<metadata>
<id>Solution</id>
<version>1.0.0</version>
<authors>cc Team</authors>
<owners>cc</owners>
<licenseUrl></licenseUrl>
<projectUrl></projectUrl>
<iconUrl></iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>c# .net</tags>
<dependencies>
<dependency id="NETStandard.Library" version="1.6.1" />
</dependencies>
<references>
<reference file="Solution.dll" />
</references>
</metadata>
<files>
<file src="Solution.dll" target="lib\netstandard1.6\Solution.dll"/>
file's node src value outpupath of my solution. (bin\Release\netstandard1.6\Solution.dll)
Run nuget pack Solution.nuspec and Solution.nupkg file created.
I put it to my package source.
Create a new .net core class library and select my Solution nuget package from local package source. It added to my project. There is no error or warning. But When I try to access a class from my Solution nuget package, it couldn't be found.I dowloaded 'Nuget Package Explorer' and opened my Solution.nupkg. Icould see Solution.dll and Solution.pdb file under lib --> netstandart1.6.
Then I searched about the error and found this :
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
After compile my Solution project it creates Solution.1.0.0-0.nupkg file and Solution.1.0.0-0.symbols. I put it to my local package source but these packages are not listed in the 'Nuget Package Manager'.
Do you have any idea?
My experience is creating package from solution sometimes crappy. Creating the package from the project file could solve the problem.
After I clean 'C:\Users\XXX.nuget\packages\Solution' folder and add package again fix my problem.
Because there is bad formatted nutget package which I tried before.

nuget and vsix repo

I have exported a template project using the export tool in VS2015. I have created a nuget package which this project rely on.
In the vstemplate file I have added:
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
<packages repository="extension" repositoryId="ViSoftVSIXPackage.Visoft.87c53ff4-9d1f-xxxxxxxxxxxxxx">
<package id="ViSoftCore" version="1.0.0" />
</packages>
</WizardData>
The repositoryId is the Id of the VSIX project.
In the VSIX project I have added the assets:
<Assets>
<Asset Type="ViSoftCore.1.0.0.nupkg" d:Source="File" Path="Packages\ViSoftCore.1.0.0.nupkg" d:VsixSubPath="Packages" />
<Asset Type="Microsoft.VisualStudio.ProjectTemplate" d:Source="File" Path="ProjectTemplates" d:TargetPath="ProjectTemplates\HMIViSoft.zip" />
</Assets>
Now, when i install the vsix, create a new project I get the following:
NuGet Package restore failed for project HMI.ViSoft4: Unable to find version '1.0.0' of package 'ViSoftCore.
When I go to Nuget Package Manager it says the package is installed but not able to find source.
I have tried this in many ways and I can't get this to work automaticly. If i manually create a package source in nuget package manager to c:\packagelocation everything is all good.
What am i missing here? Is this not supported? Do I write code in the vsix to create a package source in the nuget package manager?
I faced the same issue - Step 11 highlighted in this answer helped fix the problem. Basically this step ensures that a copy of nupkg file is created under <template install path>/Packages/

Install nuget package with a VSPackage

I'm trying to install a nuget package into a project that I am generating with a VSPackage. So far, I am able to create a solution from a project template:
Solution4 soln = (Solution4)ApplicationObject.Solution;
string prjPath = "C:\\MyProject";
string templatePath = soln.GetProjectTemplate(#"SomeProject\MyTemplate.vstemplate", "CSharp");
soln.AddFromTemplate(templatePath, prjPath, "New CSharp Project", false);
But now I need to be able to install a nuget package into that project as well. The package is located online, for example, https://somewhere.mydomain.com/nuget/feed , and has the ID PackageX.
You'll need to perform the same steps that "NuGet Package Restore" does, adding NuGet.exe, NuGet.config and NuGet.targets correctly to the solution. To see how this changes things, diff two empty solutions where one restores NuGet packages and the other doesn't.
To add your custom feed, you can add
<packageSources>
<add key="local" value="https://somwhere.mydomain.com/nuget/feed"/>
</packageSources>
to NuGet.config under the <configuration> node.
Finally, add the package name and version to packages.config in the vcproj directory and you should be all set!

Creating a basic NuGet Package

I have a small c# library that wraps Dapper.net and I want to create a nuget package for this library. I've created a folder that contains the following:
Nuget-Package\
Nuget-Package\Package.nuspec
Nuget-Package\lib\
Nuget-Package\lib\DapperWrapper.dll
Here's the nuspec
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>GoDaddy.Data</id>
<version>1.0.0</version>
<authors>Owner Name</authors>
<owners>Owner Name</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>I provide a fast and slim layer between your code and stored procedures that your application needs to use. This layer provides more straight-forward access to procs than straight ADO and less overhead than using Entity or Linq. It currently uses Dapper.Net to do some of this work.</description>
<releaseNotes>Initial Release</releaseNotes>
<copyright>Copyright 2014</copyright>
<tags>ADO Dapper Proc "Stored Procedure"</tags>
<dependencies>
<dependency id="Dapper" version="1.13" />
</dependencies>
</metadata>
</package>
I then copy the resulting DapperWrapper1.0.0.0.nupkg over to my local nuget server.
After this I attempt to install it on a console application. I open a simple console application right click on references and say manage nuget packages. I find and select my package and select install and get the following error:
Attempting to resolve dependency 'Dapper (≥ 1.13)'.
External packages cannot depend on packages that target projects.
What am I doing wrong here?
Seems too simple to fail and yet I cant seem to find a good explanation of this error anywhere.
The answer can be found here.
http://www.marcusoft.net/2011/12/creating-tools-only-nuget-package.html
Apparently nuget wont resolve dependencies unless you have both "lib" and "content" folders even if you're not using them.
Wow that's a bug IMO.
See this nuget workitem: http://nuget.codeplex.com/workitem/595
You could try adding a files section to your nuget package, referencing the files in your project.

Adding NuGet package present on hard drive (Not hosted anywhere) to a project

MY Task is to generate a NuGet package of one project containing static content and binaries. Then means by which this NuGet package can be consumed in another Project/ Solution.
I have completed the first half of the task where i was able to generate a NuGet package out of a project, but not sure how to consume this inside another project/ solution. I see only option of adding already published Projects from NuGet repository but not anything which is out there on file system/ hard drive.
Any help is appreciated.
Thanks in advance.
You need to add the directory which contains the package as a NuGet Package Source. In Visual Studio do the following
Tools -> Options
Package Manager -> Package Sources
Add the file system location and hit "Update"
After this the local package should appear in the Package Library Manager
If you are looking to change the NuGet.exe command line then create a Nuget.exe.config file and add the following
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="LocalName" value="path/to/your/package" />
</packageSources>
</configuration>

Categories

Resources