Nuget Solution-Level alternative - visual-studio-2017

I have read about Nuget Solution-Level package has been deprecated. Is there an alternative for that? or Which would be the best way to work with a multiple project solution that it is being shared between developers without breaking the references?

It seems to have be deprecated in Nuget 3.0.
According to this document: Maybe the option Manage Nuget Packages for Solution is what you want.
In VS2017, if you have a multiple-project solution, right-click the solution name in Solution Explorer and click Manage Nuget Packages for Solution to manage solution packages:
Visual Studio makes it easy to manage NuGet packages for multiple projects in a solution using this option.
Update:
There is a discussion about bringing them back.

Related

Can't use my installed NuGet package in code

I have installed NuGet package Miracle.FileZilla.Api in my VS project, but when I try to include it in my code via directive "using" VS says there's no namespace "Miracle". How do I fix it? Thanks.
I have installed NuGet package Miracle.FileZilla.Api in my VS project,
but when I try to include it in my code via directive "using" VS says
there's no namespace "Miracle". How do I fix it?
The main issue is that the VS Code tool level like nuget package manager is too low to be used in a more advanced VS IDE. And thanks to Matti for the tips and information that make this question much simpler.
VS Code is a lightweight code editor and can install many extensions for development environment tools, such as compiling, installing nuget packages, publishing, etc.It has wide compatibility with projects, including Java. But tools are not powerful enough to use in some other areas.And it is more suitable for code editing.
VS IDE is a powerful integrated development environment and includes many of the tools of the development process, such as compiling, debugging, publishing, and so on. It is better suited to developing an entire project lifecycle.
In brief, due to the powerful function of tool in VS IDE and wide compatibility of projects in VS Code, nuget package in VS IDE can be used in VS Code and in turn, the errors occurs. Or please install nuget packages and develop projects in the same version of VS.
Solution
1) Please install nuget packages and then use it in the same VS version. And l recommend you use VS IDE which is powerful enough.
2) Or you should create a project and then install the nuget package in VS and then migrate it to VS Code, you can include it in my code via directive "using" without any errors.
Hope it could help you.

Script for automated push command in Visual Studio 2017

We switched to NuGet to manage our packets in Visual Studio 2017, everyathing works fine now but to push the packages you need to first create a nuspec, create a nupkg (NuGet Package) and then push it to our NuGet Server.
All of this commands get some parameters of which some would stay the same and others need to get from the visual studio variables.
Can you recommend any scripting language that would work for this or have any other solutions for this?
Btw im a "newbie".
Can you recommend any scripting language that would work for this or
have any other solutions for this? Btw im a "newbie".
1.Since we can pack packages from xx.csproj, you can use command like nuget pack xx.csproj to create nuget packages. After that, you can use nuget push command to publish them. To push several nuget packages the same time use command like nuget push path\*.nupkg -source .... You can get some help from this link. Note if you've had the same package with same version in server,it won't automatically overwrite it. (And you can include them in a batch file like this)
2.You can try CreateNewNuGetPackageFromProjectAfterEachBuild package, install this package to your project, and it will create packages automatically for you after each build. So you don't need to manually pack them by command.(Works for my C# .net fx project).
3.For .net core projects, if you right-click the project in Solution Explorer, you can find the Pack button. After build your project successfully in VS, use the pack option will automatically package your assembly.
4.Also, assuming you're in a solution with many class library projects and you want to pack them, you can follow this document.For .net framework projects using packagereference format, add the NuGet.Build.Tasks.Pack package to the project dependencies. After that, you can use command like msbuild -t:pack xx.sln to pack all projects whose GeneratePackageOnBuild property is true.
Most of above are about how to pack packages easily. And after you get the output xx.nupkgs, nuget push *.nupkg -Source... can help you do the publish job.

NuGet Update on build (VS2017 Pro)

I'm currently looking for a way to trigger a NuGet update on build in Visual Studio 2017.
I'm using VS2017 Pro. My codebase consists of multiple solutions which break the code into layers (data access / business logic / ui / application / etc). When a solution builds, it generates one or more NuGet packages which are then consumed by projects further up the 'food chain'.
Automating the NuGet update on our build server is trivial, however it would be nice if we could configure our development environments such that it always attempts to get the latest NuGet packages on build akin to how Package Restore works.
I've come across a lot of information regarding older versions of Visual Studio/NuGet that include updating the auto-generated nuget.targets files, however these aren't created in VS2017 with NuGet package manager 4.6.x (unless I'm doing something wrong!)
Any help or advice would be greatly appreciated.
NuGet Update on build (VS2017 Pro)
If pre-build events are too late for you, you can try to add a new project to the solution with pre-build event/post-build event to update the nuget packages, which uesd by other projects/solutions:
<YourNuGetPath>\nuget.exe update "<YourSolutionPath>\xxxx.sln"
Or
<YourNuGetPath>\nuget.exe update "<ThePackages.configFilePath>\Packages.config"
In this case, you can build this new add project to get latest NuGet packages for these projects/solution using nuget packages.
Besides, if you do not want to build this project before those consuming nuget package projects, you can let those projects reference this new add project, Visual Studio will build it before building those consuming nuget package projects.
Hope this helps.

PackageReference for NuGet packages in C++ projects

I'm part of a project where we use packages.config files for NuGet packages in Visual Studioe and then include each package dependency through the Import statement in our project files.
This works fine if you always want the packages, but we have some conditional packages that we'd like to exclude if the developer doesn't need/want it. I found the PackageReference tag, that would make the dependency much cleaner and would let us include the packages conditionally.
It seems to be fully supported in C# projects, but I can't figure out if it's supported for C++ projects or not.
I have tried deleting all of our packages.config files and replacing all references with PackageReference tags, but the PackageReference tag doesn't seem to be picked up by the package manager. I've gone through all the "migration tools" that I could find for Visual Studio too, with no luck.
Is it possible to use it for C++ projects? If not, is there a workaround that lets me exclude certain packages conditionally?
I'm using Visual Studio Professional 15.6.7.
Is it possible to use it for C++ projects?
At this moment, PackageReference is not yet supported for C++ projects. NuGet team is evaluating it to support for future releases. You might had made it work through some hacks but if you create a new c++ project and tries to install this package as PackageReference, it won't allow you. So I recommend you to continue using packages.config for your c++ projects and libraries.
Besides, you can add your request or vote for this feature on the Visual Studio UserVoice site: Use PackageReference in vcxproj. When there are enough communities vote and add comments for this feedback, the product team member will take this feedback seriously.
If not, is there a workaround that lets me exclude certain packages conditionally?
You can include the conditional references in the custom targets file and deploy the dlls in the tools folder of the package so they are not added as references by Nuget automatically.
certified: NuGet update and conditional references
Hope this helps.
While not supported, it IS possible to use PackageReference with C++ projects.
If you check the comments at https://developercommunity.visualstudio.com/t/use-packagereference-in-vcxproj/351636, there are a couple examples on how to enable this.
Note, the Visual Studio experience may degrade, but building with MSBuild (command line) has had no issues.
Note, we currently use PackageReference for VCXPROJ projects in ReactNativeWindows.
Being an unsupported feature, a couple hacks are required for Visual Studio compatibility, but all in all it works.
https://github.com/microsoft/react-native-windows
To summarize the other answers and provide some more recent information:
PackageReference is not officially supported in C++ projects, as it's not fully integrated with NuGet and Visual Studio, but:
MSBuild supports PackageReference, and Visual Studio 16.9 and later (this is 2019) have some integration implemented as well.
The full steps are described in a comment of the Make the PackageReference support general purpose for all languages PR, but basically:
above the project folder, create Directory.Build.props file with the following content:
<Project>
<Import Project="$(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.props" />
</Project>
and Directory.Build.targets file with the following content:
<Project>
<Import Project="$(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.targets" />
</Project>
in the project file add the following in the Project node:
<ItemGroup>
<ProjectCapability Include="PackageReferences" />
</ItemGroup>
and
<PropertyGroup>
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
</PropertyGroup>
(or similar moniker)
Reload the project.
The above will make MSBuild and Package Manager work, with some caveats, e.g. you have to "Save All" after modifying packages through the UI, package references are not shown in the References node in the Solution Explorer, etc.
Note that Augustin Popa, which is PM for the Visual C++ team, gives an explanation why updating projects to the partially supported PackageReference may not be a good idea, because they have other plans for the future:
Our concern there is that if developers do the work to migrate to C++ PackageReference, they would later realize that we don't intend to provide ongoing support and want them to move to something else. I expect that would be a frustrating experience.
The "something else" he's talking about is probably a better integration with vcpkg, as discussed in his comment to the Use PackageReference in vcxproj feature request for Visual Studio:
From our side, we have to consider the needs of a very large user base with diverse requirements, which include support for CMake projects, installing packages for non-Windows platforms, and providing a better story for acquiring libraries that are actually compatible with the executable they attach to and with each other (achieved with vcpkg today). NuGet is not designed to handle these scenarios[...]
And still, even dev teams inside Microsoft are using the PackageReference approach, as seen in this comment for the same feature request:
We have made this work in React Native Windows via the following Pull Request.
As it’s been mentioned, MSBuild can handle this case for C++ (VCXPROJ) projects.
First-class support in the Visual Studio IDE would be highly beneficial for existing projects wanting to drop the traditional NuGet.exe/pakcages.config mechanism but can’t afford to rewrite the whole project to adjust to VCPKG.
At the very least, there is a drive space benefit to using PackageReference, so it’s not only about aesthetics.

The nuget packages nightmare in VS 15.5.1

I have a solution with 15 projects. To better manage my references/dependencies, I have gathered all shared nuget packages in one .net core project. All projects requiring these packages have to reference it.
This works fine but it becomes a nightmare to update nuget packages.
Few days ago, a newer version of X.PagedList was released. After updatin the package, I got the following error messages
Assembly 'XXX' with identity 'XXX' uses 'X.PagedList v7.2.0 ...' which
has a higher version than referenced assembly 'X.PagedList' with
identity 'X.PagedList v7.1'
I tried to clean the solution, rebuild, remove/re-add the nuget package with no luck. I ended-up removing the nuget cache, restarting my computer and restoring all nuget packages... That can't be the easiest solution.
Earlier this month, I had similar issues. I was not getting an error, but it was like all my references were gone. All my import statements were detected as errors...
Am I the only one experiencing that kind of issues? Is there a way to make package update easier?
My environment:
Visual studio 2017 Community 15.5.1
ReSharper 2017.2.2
AWS Toolkit
1.) Delete the .vs directory in your solution folder or the folder above it. This is magic.
2.) Open the .config file in every project and delete all the binding redirects.
3.) Delete bin and obj folders for all projects.