How to use Nuget in SharpDevelop? - nuget

I am newbie in SharpDevelop and want to download Nuget packages. But I couldn't find any information about this topic on google. How to get Nuget packages in SharpDevelop?

I have taken new nuget.exe from here, put it to c:\test, in cmd -> cd c:\test I then entered nuget to get all info, and tried then nuget install Newtonsoft.Json -version 13.0.1 - getting "nuget argument can not be null or empty" - advice helped - tried ONLY nuget install Newtonsoft.Json - result "nuget unable to find package" - advice helped - I created nuget.config file with such content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
and put it near my new nuget.exe previously loaded...
PROFIT: nuget install Newtonsoft.Json - RETURNED needed nuget package's dlls of Newtonsoft (JSON.NET)...
and through (left-mouse-button in your SharpDevelop project) Referencies - AddReference -> .NET Assembly Browser -> Browse -- you can choose necessary c:\test folder (in my case) and dll version in it and add it to your project...
the oldest version (4.0) is better choice for best compatibility with both OS with NET.Framework 4.0 and OS with NET.Framework later versions as well

Related

Nuget Packages Not Restoring

I recently migrated my projects from using PackageReferences to a package.config file. For awhile I've been able to call nuget.exe restore ...\Solution.sln and everything has looked fine. Now when I build I appear to be missing references to my packages used in my package.config files.
I removed all of the 'PackageReferences' from the .csproj file and added a 'packages.config' to each project that look like the following:
Ex 1:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net31"/>
</packages>
Ex 2:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AspNetCore.HealthChecks.SqlServer" version="3.2.0" targetFramework="net31"/>
<package id="Newtonsoft.Json" version="13.0.0" targetFramework="net31"/>
<package id="System.ServiceModel.Security" version="4.9.0" targetFramework="net31"/>
</packages>
I have Automatically check for missing packages during build in Visual Studio checked in the NuGet Package Manager options of Visual Studio. I am using Visual Studio 2019 16.11.15 and NuGet 6.2.0.
Going to package manager and putting in update-package -reinstall outputs No package updates are available from the current package source for project 'ProjectName'.
If I right-click a packages.config file and select Migrate packages.config to PackageReference... I get an Operation Failed error. Is something wrong with my packages.config files? Is there anything else I can check?
Edit: I have attempted to delete all of my .vs, obj, and bin files. Also my csproj files begin with either <Project Sdk="Microsoft.NET.Sdk"> or <Project Sdk="Microsoft.NET.Sdk.Web">
We can only see migrate from packages.config to PackageReference in offical documatation because PackageReference is something newer. Reverse migration is not a good option.
You said you want to use packages.config with nuget restore so all dependencies can always be downloaded/updated after a fresh pull. You can refer to this page, it gives us many methods to restore packages.
For example, you can use “msbuild -t:restore” in PackageReference to restore packages. See this.

NuGet Pack -- Failed to retrieve information from remote source

I am trying to run:
nuget pack project.csproj
but because of the directory structure of the project:
A\B\C\Project
it keeps saying:
NuGet.Protocol.Core.Types.FatalProtocolException: Failed to retrieve information from remote source 'A\B\Packages', which it really should be 'A\Packages'. How do I change where NuGet looks for packages while establishing dependencies.
I have tried putting a NuGet.config in both the project directory as well as the Solution (in .nuget). I added this to the file:
<config>
<add key="repositoryPath" value="A\Packages" />
</config>
in both places and it made no difference (it always says A\B\Packages).
VisualStudio 2019: Tools > Nuget Package Manager > Package Sources:
Select nuget.org and specifically unselect the others options
Add NuGet.org reference in the package source
Go to tools -> NuGet package manager-> package manager settings
Select NuGet Package manager and then Package sources
Add the following source library.
Name: NuGet.org
Source: {"\Https://api.nuget.org/v3/index.json}
The error is a bit weird, but is already mentioned here.
It looks like NuGet by default expects a packages folder at the same location as the .csproj file.
I also had a custom project structure where the .sln was located in another folder.
At least I worked around this by creating a Symbolic link like this (open cmd with admin rights):
cd <your .csproj location>
mklink /d packages "C:\path\to\actual\packages"
This way NuGet thinks the packages folder exists and should be able to create your package.
For me it worked by adding NuGet.config in solution folder.
I was facing similar issue with core 3.1 and trying to upgrade package 'Swashbuckle.AspNetCore.SwaggerGe'.I found that i was doing typo in Package source url. I have corrected it [Tools => Nuget Package manager => Package manager setting => Package Source ] and issue got resolved.
If you use packages that have Semantic Versioning 2.0.0, please make sure that you are using the V3 feed, https://api.nuget.org/v3/index.json, in the NuGet configuration.
The issue may be caused by the way the nuget looks for the packages folder. It looks for a .sln file by traversing up the directory structure. If, in your case, directory A\B contains a .sln file then nuget will assume the packages folder would also be there.
On OSX you can add a symlink to trick nuget into building.
Run the following in the project folder to make nuget read from the parent (solution) directory that have a packages folder:
ln -s ../packages packages
In my case, I unchecked ALL the package sources except the one that I needed which was NuGet.org from NuGet Package Manager >> Package Sources. After this, the NU1301 error was gone.
In the case of Rider IDE another problem could cause this error:
if you configure your NuGet sources in the project let the Username and Password in the Rider Ui empty and instead add manually this section (packageSourceCredentials) to your NuGet.Config in the project folder:
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="YourNuget" value="<your_nuget_url>" />
</packageSources>
<packageSourceCredentials>
<YourNuget>
<add key="Username" value="<Username>" />
<add key="ClearTextPassword" value="<Password>" />
</YourNuget>
</packageSourceCredentials>
</configuration>

nuget pack ignores package.config dependencies

I cannot get nuget pack X.csproj to recognize package dependencies in a project. Amazingly, when packaging, the diagnostic message “Found packages.config. Using packages listed as dependencies” is printed, but in the end the <dependencies/> tag in the .nuspec file inside the package is empty.
The packages.config for the project does indeed contain references:
<packages>
<package id="SmartAction.Logger" version="1.0.2.0" targetFramework="net40" />
<package id="SmartAction.Pervasive" version="1.0.1.0" targetFramework="net40" />
</packages>
To narrow the problem down, I removed my own parallel .nuspec file, and mostly all switches from the nuget pack command:
> nuget pack libToneDetection.csproj -prop Configuration=Release
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Attempting to build package from 'libToneDetection.csproj'.
Packing files from '[snip]\Core\ToneDetection\libToneDetection\bin\Release'.
Found packages.config. Using packages listed as dependencies
Successfully created package '[snip]\Core\ToneDetection\libToneDetection\SmartAction.Audio.ToneDetection.1.0.0.0.nupkg'.
NuGet Version: 3.3.0.212
The only difference I can spot with this project is that its name is different from package name (I am trying to maintain them in sync but this is older stuff I am repackaging).
I doubt I had ever seen this before. I am finding questions on SO from people trying to prevent references in packages.config from becoming dependencies of the package, but none from those trying, like me, to beat the reverse problem. Help!
Addendum. I copied the project out of the solution with other projects to a temporary directory and rebuilt the package from there. Now one of the two dependencies from packages.config was added to the package:
<dependencies>
<dependency id="SmartAction.Logger" version="1.0.2.0" />
</dependencies>
Thinking of the differences between the two, the SmartAction.Logger package depends on SmartAction.Pervasive. But the package I am compiling really uses both.
To me, either behavior looks incorrect. Am I hitting a nuget bug, or a cryptic complex feature?
Xref: Opened https://github.com/NuGet/Home/issues/1867

Build project - Nuget Error

The error occurs only on one machine.
Attempts
Wrong paths
I thought the path of any source may be wrong, so I opened the NuGet.Config to check and the 3 paths are correct and there!
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="Nightly ASP.NET Web Stack" value="http://www.myget.org/F/aspnetwebstacknightly/" />
<add key="Bind Solution" value="W:\Cloud\Dropbox\Bind Defaults\Nuget Repository" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
</activePackageSource>
</configuration>
Nuget.exe not exist
Checked on .nuget folder and .exe is in the directory!
Checked in Path of windows and there is!
I tried to run the command manually and it run successfully!
nuget install packages.config -source "" -NonInteractive -RequireConsent -solutionDir "W:\C
lients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\ "
Full error:
Error 1 The system cannot find the path specified. CreditoImobiliarioBB.Domain
Error 2 The command ""W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB.nuget\NuGet.exe" install "W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\CreditoImobiliarioBB.Model\packages.config" -source "" -NonInteractive -RequireConsent -solutionDir "W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\ " " exited with code -1. CreditoImobiliarioBB.Domain
Considerations
Only projects that have local packages (Source is key="Bind Solution" value="W:\Cloud\Dropbox\Bind Defaults\Nuget Repository") is that they are in trouble. And recently the location of packages moved to another directory (in this case to W:\Cloud\Dropbox\Bind Defaults\Nuget Repository).
I had a similar problem recently, I fixed it by doing this:
Update Visual Studio to the latest version. (Extensions and Updates - Product Updates)
Update Nugget to the latest version. (Extensions and Updates - Visual Studio Gallery)
Clear the Package Cache. (Options - Package Manager)
Rebuild the solution.
Hope it helps.
I ran into a similar problem with NuGet.exe and WG.exe for WebGrease. I realized that with my Virus Protection turned on, it wasn't allowing the .exe files to come down properly. Once I disabled my Virus Protection, I was able to get everything I need (company is using McAfee).

Packing NuGet projects compiled in release mode?

Is there some way to make a NuGet package using code compiled in release mode? Or is there some reason I should only publish (make available locally, in this case) packages compiled in debug mode?
Every time I call nuget pack from my project directory, where I have the nuspec file below, on code I have only compiled in release mode, it complains about not finding the DLL in the debug folder ("\bin\Debug\SomeProject.dll"). If I compile it in debug mode, those files are there and it packs them up as it should.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<iconUrl>http://somewhere/project.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
</metadata>
</package>
You can solve it like this:
NuGet.exe pack Foo.csproj -Prop Configuration=Release
(reference)
If you are using a post-build event and you want to create a package whether using Debug or Release configuration you can setup the post-build event commandline like so:
"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)
To have NuGet automatically use Release mode when you run nuget pack, do the following:
Open your .csproj file in a text editor.
Find the following line:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
In this line, replace Debug with Release.
Save changes.
The answers here are good, but I was having a lot of problems with this for a .NET Standard project. I had a project that was only going to publish Release binaries, but it wasn't respecting my default build output path.
I added this to my CSProj which then enabled me to use the accepted answer here.
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>
Chiming in here.
My build profile would build the DLLs to bin\<arch>\Debug|Release.
I was able to point to my folders by running the nuget command as follows:
Notice how I used the -p option.
PS > nuget pack -p Configuration="x64\Release"
Attempting to build package from ...
...
Found packages.config. Using packages listed as dependencies
...
- Add a dependency group for .NETFramework4.7.2 to the nuspec
Successfully created package...