How do you configure a VS2015 C# project to put the NuGet packages on build in a lib directory? - visual-studio

I am using Visual Studio 2015 Community. I have got a C# project with a bunch of NuGet packages. When I build the project the NuGet assemblies get copied into bin\Release but I don't want them in the root directory of my application, I want them to be put in a lib subdirectory.
The output path build setting doesn't do what I want, it changes the general output directory. I think that it's Visual Studio which copies the NuGet assemblies on build.
I like my projects organized and don't want a bunch of dependency DLLs in the root folder.

One suggestion is that you could think about using the init.ps1. When the NuGet package is installed for the first time or every time the solution is re-opened in Visual Studio, Init.ps1 will runs once for your solution.
Reference Ryan Vice's share us the detailed steps about how to let NuGet copy dlls to [solution root]\lib in this case:
How to copy Nuget content files relative to the solution root

Related

Package target doesn't include bin\x64 folder but VS2019 did

I think I have various beads on why this may be happening, but I can't quite put all the clues together.
We were building an ASP.NET app in VS 2019 with a nuget dependency (Microsoft.Data.SqlClient.SNI.1.0.19235.1 if it matters). I've used msbuild -t:package and in VS 2019, it would spit out bin\x86 and bin\x64 folders with the DLL from that nuget package. That package step would spit out a zip file and opening that up you can see the x86/x64 folders in there.
We upgraded to VS 2022 and the CPU arch folders are no longer there. I can see them get created in the working directory, but not in the package output.
Nothing in the project has changed. It's set to target "AnyCPU" and Framework 4.6.2. The command we're using to build hasn't changed either. As far as I can tell, it's just the upgrade to VS 2022.
I know VS 2022 is now 64-bit native, so I have a suspicion that's in play here. Any ideas on why those CPU-architecture folders are no longer included in the zip package? And how to get them back in there?
Thanks!
According to your description I make some test, hope it can help you:
Check your Configuration Manager under Build in the menu and add new Platform you need.
Build the project in Batch Build under Build in the menu.
We can see that .dll files are created in the same path so it will be covered.
Open the project file.(Right click on the project and Unload Project then right click again an choose edit project file)
You can see code like this:
Change the OutputPath to “bin\x64\Debug\”, ”bin\x64\Release\” and so on.
Reload the project and rebuild the project in Batch Build.
About how to Pack multiple platforms into one package you can see this(Pack multiple platforms into one package, using dotnet pack ).
If it helps anyone, since my problem was specifically with the SNI.dll not being emitted in the x64/x86 folders, my workaround solution was to upgrade the Microsoft.Data.* libraries to a newer version. The x64/x86 folders are still not emitted, but I now see Microsoft.Data.SqlClient.SNI.x64.dll and Microsoft.Data.SqlClient.SNI.x86.dll files in the root bin folder.
It doesn't answer the original question, but at least it got me moving.

Add a project.json based project to a .sln file without using Visual Studio

We have developers that are using VS Code on Linux, Windows, and Mac. We also have developers that are using full Visual Studio on Windows. A problem arises when the former (including me) do not add their projects to the solution, and the latter therefor do not see the projects in the solution.
How can developers add their project.json projects to a sln without having to open Visual Studio?
Nowadays .NET Core SDK allows working with sln files.
Imagine you have a root folder for the solution. All the projects are located under src and test folders.
Then from the solution folder run something like this:
dotnet sln add ./src/Insurance.Domain/Insurance.Domain.csproj
dotnet sln add ./test/Insurance.Domain.Tests/Insurance.Domain.Tests.csproj
You can list the projects in the solution runing
dotnet sln list
Note:
The solution provided above is not going to work with project.json files. Anyway project.json format is obsolete now and you can easilty migrage to csprojs with the latest SDK. Just run in your project folder:
dotnet migrate
and you are good to go.

Adding nuget files to Different folders in a Visual Studio project

I have a private hosted nuget repository with a .nupkg including several DLL files. These files are compiled C++ plugins for interacting with hardware, printers, cameras etc. I also have a c# project, which is set as the startup project in my solution. The usual way I'm adding these DLLs is to press "Add Existing Item" on my project and set the Build Action to Content and Copy to output Directory to Copy if Newer. So when built, the DLLs can be found in the output directory.
I want to simply this process by having these files in a nuget repo, but when pressing the "Manage Nuget Packages" on the project, these files are only added as Reference. How can I define where nuget is adding my DLL files? Is it event possible?

Branching in VS 2010 with TFS loses NuGet package references

I am using Visual Studio 2010 with Team Foundation Server 2010. I have created a root for a project which uses AutoMapper and EntityFramework which I installed for the solution using NuGet package manager.
When I branch from the root the resulting branch has a yellow warning triangle in the references section for the AutoMapper and EntityFramework. I have tried uninistalling the packages and then reinstalling but nothing allows me to include these references and build the solution. The only message I get is that the package aready exists.
All suggestions gratefully received.
I have solved the problem. The root solution was a created from existing projects from another source and there were some NuGet package references in the packages.config files in the project folders. The steps were:
Delete the packages folder (if it has been copied over) from the root of the solution
delete any NuGet references to the packages from the solution file (.sln)
delete any NuGet references from the packages.config files
Using Manage NuGet Packages for the solution to uninstall any packages
Reinstall from the solution level
And then all was fine.

Do Nuget packages need to be added by every developer who works on same VS project?

I've added some libraries to a VS 2010 solution using Nuget (RestSharp, Twilio, etc.). When I pull the same solution down to a new PC from TFS and try to build it, all the references to those assemblies are broken (error "namespace cannot be found..."). Is it necessary for each developer who works on this VS solution for the first time to independently install the same Nuget packages on their PCs?
Thanks,
Jim
As Andrew already have said it's all about the packages' location.
Either you have to check in the entire packages folder with all the packages, or each developer have to install the packages after first checking out. But there is a better way to do this, namely to use NuGet Package Restore - which will automatically install all missing packages when the project is built.
If you use package restore, you only need to check in the repositories.config into your VCS. With TFS you can cloak the entire packages folder except for the repositories.config, so that TFS doesn't annoy with pending checkins for new packages.
Also see this answer for guidance on how to use TFS + NuGet.
No, but you need to be sure the assemblies are all included in the same relative path so Visual Studio can find them. You can include the solution's nuget packages directories, which is where I think it stores a copy of the libraries to be referenced by the project(s).
Incidentally, including said diretories may be effectively the same as "installing the packages". If you include all the files that NuGet uses in its management of packages, NuGet will behave the same as if you had installed them. But you don't need to do the actual package install via NuGet for it to work... or even have NuGet installed in Visual Studio in the first place. It's just a matter of the proper files being where the Visual Studio project files expect them to be.

Resources