Net Standard - Nuget package publish package as "add" keyword in command line - visual-studio-2017

I create a new Net Standard library, and I would like to publish the package to a local nuget repository.
In order to achieve it, I have two ways: using the command line, or using the publish option offered by Visual Studio.
Using the command line I use the "add" keyword from the command line (due to the fact it is a non-http package source), and it works fine, it create the nuget package with its nuget.sha512 file.
Using the publish option offered by Visual Studio, I've not been able to replicate the previous behavior, because it replicate the "push" keyword in the command line.
In the same local repository I can't hold two different packages, one with .nupkg.sha512 file and the other without it, because the nuget package manager will find only these packages without the ".nupkg.sha512" extension.
Is there any way I could tell to Visual Studio to replicate the "add" behavior using the publish option?
Thanks in advance.

Is there any way I could tell to Visual Studio to replicate the "add" behavior using the publish option?
I am afraid there is no such directly way that you could tell to Visual Studio to replicate the "add" behavior using the publish option, because the add command is only supported by NuGet CLI. We could not use it directly with publish option.
As workaround, you can add custom target to call NuGet CLI when you publish your project.
To accomplish this, edit your project. Then at the very end of the project, just before the end-tag </project>, place below scripts:
<Target Name="AddPackage" AfterTargets="GenerateNuspec">
<Message Text="Add Package to the local nuget repository!"></Message>
<Exec Command="<PathOfNuGetCli>\nuget.exe add "<PathOfPackage>\xxx.1.0.0.nupkg" -source "<localNuGetRepository>""></Exec>
</Target>
Note: Since this custom target depends on the target GenerateNuspec, it will be executed twice, but not worry about it, it will not have any actual operation when it is executed in the first time(The package has not yet been published to the specify folder).
Hope this helps.

Related

Dependency injection error pops up whenever I try to install a certain Discord Package

I'm really new to programming, but I felt like trying out some bot-development for my discord server, like one that will occasionally say hello to people when they join, however when I tried to install one of the Discord packages I got this error
Unable to resolve dependency 'Microsoft.Extensions.DependencyInjection'. Source(s) used: 'discord.net', 'Microsoft Visual Studio Offline Packages'.
Unable to resolve dependency
'Microsoft.Extensions.DependencyInjection'. Source(s) used:
'discord.net', 'Microsoft Visual Studio Offline Packages'.
This error message always occurs when you want to install the package whose dependency package is not found. For example, I created a custom package(MyCustomPKG) that depends on Microsoft.Extensions.DependencyInjection.
And now I'll get the same issue if nuget can't find the Microsoft.Extensions.DependencyInjection in all available package sources.
To resolve that issue:
Add nuget.org(https://api.nuget.org/v3/index.json) as package sources and make sure the checkbox is enabled.
In addition: If you're not using VS IDE, instead you're using Nuget.exe+Nuget.config file, add this line(<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />) to Nuget.config.

VSTS feed "refresh" mechanism in Visual Studio

I have set up a VSTS nuget feed. And I have pushed some packages two days ago. I was able to add those packages to my project. But I needed to push an other version for one of them. Made new nupgk version, pushed it and I can see it in VSTS, I can download it from there, Visual Studio 2017 is also listing it correctly but when I try to install it, I am getting an error:
Package 'whatever 1.0.1' is not found in the following primary source(s): 'https://whatever.pkgs.visualstudio.com/_packaging/feedname/nuget/v3/index.json'. Please verify all your online package sources are available (OR) package id, version are specified correctly. 0
What I have tried:
- waiting around 10 minutes
- restarted Visual Studio several times
- pasting the above url into a browser and refreshing it manually several times
One or more of these helped. But I would like to know if there is any canonic solution for that.
I used the answer widget to have some formatting. Still, this might not be "the" answer, as I don't know the mechanism beyond. But it looks to be a workaround.
Steps:
Create a solution with a library project (let's call it L01)
Add another library project to the solution (let's call it D01)
Make a nuget package from L01 (version 0.0.1)
Push the package to your VSTS feed
Manage packages for project D01 and browse your feed
Package L01 v0.0.1 will be listed
Add it to project D01, it will work
Edit L01 nuspec file and change version to 0.0.2
Build and push the new package
Go back to project D01 and refresh the package list. The update will be shown.
Try to update. It will fail with the error message from my question.
Now go to folder %localappdata%\NuGet\v3-cache (or equivalent)
Locate the folder corresponding to your feed and open it
Locate list_l01.lib_index.dat (where l01 is the package name) and delete it
Go back to project D01 and try to install the update. It will succeed.
Would be good if others could confirm. I have reproduced this several times.
Seems you are trying to download the package or packages that where just freshly pushed to VSTS nuget feed.
Since Visual Studio 2017 is listing it correctly, then the issue should not related to the feed on VSTS server.
If this occurs very recently(download the new refresh package) and your package is very large, this maybe a network delay. Suggest you use a fiddler trace when this issue happens again. This makes "some" sense, what you see is probably an incorrect propagation of pushed packages showing up in the search results but not yet available to download.
And some other also encounter the same issue and error as you.
FYI, I've been seeing this exact issue in the past month or so.
Switching between sources, uninstalling and reinstalling are some work
arounds, but not 100%. Pushing my own packages up to VSTS and then
it takes like 15 minutes to finally get it to install.
More details please take a look at this similar issue Package update not found when updating via Visual Studio Solution

Confirm that the <UsingTask> declaration is correct

We have downloaded a project from TFS and after restoring Nuget packages we are getting below error:
Error 5 The "ValidatePackageReferences" task could not be loaded from the assembly projectPath\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.Tasks.dll. Could not load file or assembly 'file:///projectPath\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. projectName
We have not used Task anywhere. It seems it is being used internally. Any pointer how to get rid of this error?
Mostly it looks like its because of wrong version of NuGet package. But not sure whats root cause.
We are using VS 2013 Update 5 version.
First search "Microsoft.Bcl.Build.Tasks.dll." nuget on google. Then a link will be opened with named "https://www.nuget.org/packages/Microsoft.Bcl.Build/". Then copy the package name shown on the site like this
Install-Package Microsoft.Bcl.Build -Version 1.0.21
Then Open the Visual studio , Goto Tools>Nuget Package Manager>Package manager console. Now paste the copied install package,Install it. Then restart the VS.Issue will be solved.

Netstandard.Library 1.6.1 blocked by project

I've created a brand new solution and project in VS2017 RC and for some reason I can't use the latest version of the NETStandard.Library package.
There's no code in the project and it's the first project in the solution.
When in the NuGet package manager it's listed in the dropdown, but marked as blocked by project.
Any ideas?
You need to execute the command in Package manager console for your project
Install-Package NETStandard.Library
The NETStandard.Library package is no longer meant to be upgradable through the package management UI. The "SDK" component of the project emits this reference automatically and marked read-only.
This behaviour can be overridden through a property in the csproj file:
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
If you delete a line like this from your csproj file, you'll get the newest version that VS or the CLI knows about.
This property is usually added when migrating from project.json to csproj. In this case, you can safely remove it.

How to create nuget package for native C++

I want to publish package about sdl_mixer, it's a native package. I did as tutorial said. I put .dll .hand .lib files into package content, but the final package didn't work. So what is right way to create c++ nuget package?
Another question: I found in nuget, most native c++ package are published in two packages, for example:
sdl2_ttf.v140
sdl2_ttf.v140.redist
What is difference between those two files? And how can I publish my packages like that?
Update:
I followed the tutorial on how to publish native packages. I have written the following autopkg file
nuget{
nuspec {
id = MySdl_mixer;
version :2.0.0.0;
title: sdl mixer;
authors: { Sam Lantinga, Stephane Peter, Ryan Gordon};
owners: {spartawhy117};
licenseUrl: "http://libsdl.org/license.php";
projectUrl: "http://libsdl.org/index.php";
iconUrl:"";
requireLicenseAcceptance:false;
summary:Nothing;
description: #"SDL_mixer is a sample multi-channel audio mixer library....
";
releaseNotes: "Release of C++ ";
copyright:Copyright 2015;
tags: {v140 ,sdl_mixer , native, CoApp };
};
files {
#defines {
Include = include\;
Bin = bin64\;
Lib = lib64\;
}
include:{"${Include}*"};
[x64,v140,debug,desktop]{
lib: ${Lib}SDL2_mixer.lib;
bin: ${Bin}SDL2_mixer.dll;
}
[x64,v140,release,desktop]{
lib: ${Lib}SDL2_mixer.lib;
bin: ${Bin}SDL2_mixer.dll;
}
};
targets {
Defines += HAS_SDLMIXER;
};
}
Running the command Write-NuGetPackage .\sdl_mixer.autopkg returns an error unexpected input of the end. What is the problem here?
I searched around for days until I found there is really no help out there on the internet at all. I did managed to piece together how to do it, and through trial and error got it working well. Which I have documented here:
https://digitalhouseblog.wordpress.com/2019/08/22/how-to-make-a-nuget-package-for-c/
But I'll summarize here anyways:
Gather or stage your native library files into a folder of your
choosing.
Create a *.nuspec file in that folder.
Edit the *.nuspec file to include the files you want to include in your package.
Create a *.props file
Call nuget pack to create the package.
Push the nuget package to a feed somewhere.
Create a packages.config file.
Edit the visual studio project file to import the *.props file
Notice that the nuget tools inside the visual studio IDE are NEVER used. You have to do a LOT manually. See the link for full details and explanations.
You can use CoApp PowerShell tools to create the Native Nuget packages easily.
Creating Native Packages
If you’re interested in publishing your
native libraries via NuGet, you can choose to create the NuGet
packages manually. However, there’s an easier way--the CoApp project
volunteered to write C++ oriented tools to create NuGet packages, and
they have released a beta version of their tools. These tools simplify
the process of generating the MSBuild files and NuGet packages from
existing header and library files--you just need to create a
configuration script to describe the contents of the package and then
run the tools to generate the NuGet package.
Refer to this link for more detailed information: Support for Native Projects.
If you want to do this from Visual Studio C++ using a Visual Studio Solution and projects.
Look at my answer here.
Create Nuget package for C++/C Visual Studio Solution projects
The above question seems to be Linux.