Can't use my installed NuGet package in code - visual-studio-2017

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.

Related

Building and running unit tests with Visual Studio build tools

I am adding unit tests to an existing C++ Visual Studio projects, using the Google Test adapter.
It's all running fine on my computer with Visual Studio 2019, but when I try to run them on the build server I get the following error
error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets.
However, we're not using NuGet for package management. I tried installing it but complained about missing folders. This is not a .NET project, so I think that's a red herring.
I was able to install the Google Test adapter on my computer using the Visual Studio Installer, but it does not show up as a part of the VS Build Tools on the build server.
Running msbuild -t:restore does not help, it just reports "nothing to do."
I don't understand why the Google Test adapter isn't available for VS Build Tools, since it seems to be required in order to build the unit tests. Does anyone know why it doesn't work? What's the best practice for handling this?
Thanks!
The problem is that your c++ project has missed the content of googletest nuget package. So the solution is to restore the whole nuget package in your c++ project.
Update 1
First of all, take a brand new backed up project and restore it to when the problem started.
Besides, msbuild -t:restore command applies to projects with PackageReference nuget management format.
Since your c++ project used packages.config nuget management format, msbuild -t:restore will not work. See this official document.Instead, you should use nuget restore command.
This command works for your current project and running this command will restore the nuget packages and then you will never face the issue.
Before using it, you should download nuget.exe CLI and config its path into System Environment Variable PATH so that CMD can invoke nuget.
The steps about configing nuget.exe, you can refer to this link.
Steps
1) delete packages folder under the solution folder
2)Then, open build tool, run:
nuget restore xxx\xxx\xxx.sln(the full path of solution file containing the c++ project and the unit test project)
Then, you can build the project with the command. And I hope the error will disappear.

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.

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.

NServiceBus.Host.exe is missing while installing NServiceBus.Host on aspnetcore 2 in visual studio 2017

I am trying to run NServiceBus with AspNetCore2 on visual studio 2017. While I install NServiceBus(Version 7.0.0-beta0001) and NServiceBus.Host(Version 8.0.0-beta0001) through nuget, it says package installed successfully.
However, when i try to check installed dll's and exe files of NServiceBus within bin/debug folder, it's not there.
Quick observations i made are, NServiceBus (version 7.0...) is installed correctly whereas NServiceBus.Host (version 8.0....) is showing a warning message under nuget folder in visual studio:
Package 'NServiceBus.Host 8.0.0-beta0001' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
Please help me to resolve this issue or point me to correct question if it's already been answered (which i could not find in SO)
NServiceBus.Host is being phased out for the reasons specified here. Long story short, in .NET Core it does not add much of a value and has more cons.
You can however, still run the NServiceBus process in a console app. Have a look at the self-hosting sample here.

Adding Casablanca Dependency VS2017

I recently upgraded to VS2017 and I'm looking to start doing more C++ work. I've not used VS or C++ in a good while (and even at that I was a C++ novice).
I'm trying to install Casablanca, aka CPPRestSdk (https://github.com/Microsoft/cpprestsdk) but I can't seem to manage it.
I've tried installing it through NuGet but I'm not sure exactly what I've to link to my project, and I've tried vcpkg - to which I've downloaded via the instructions but I have no clue what to do there.
All the materials I find for this apply to earlier VS editions and don't appear to work when I try them. Has anyone had such luck with getting this to work? If not, is there an alternative that I can use that has clear installation instructions?
Thanks
I recently moved a C++ REST SDK based project from the older NuGet package to the recent VCPKG based 2.10.1 release. Apart from Visual Studio 2017 with the C++ for Desktop workload make sure you have Git for Windows installed. Clone the VCPKG repo from GitHub with
git clone https://github.com/Microsoft/vcpkg
I'd recommend using a directory not having any spaces in its path, otherwise some builds might fail. Change into the VCPKG directory and run the bootstrap script:
.\bootstrap-vcpkg.cmd
This will compile the package manager itself. Afterwards you can install the C++ REST SDK with
.\vcpkg install cpprestsdk cpprestsdk:x64-windows
This will download all required libraries and takes quite a while. For usage in Visual Studio you have to enable the system wide integration with
.\vcpkg integrate install
This requires elevated privileges the first time but afterwards the C++ REST SDK is available in any Visual Studio C++ project. Follow the instructions for getting started. As soon as you include a C++ REST SDK header into your project the linking is taking care of automatically by Visual Studio.
For consumption in a CMake project you have to pass the VCPKG toolchain file to the CMake command, e.g.
cmake -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake
Referencing the C++ REST SDK from CMake is described in the project repo's README.