I have a group of DLLs: some are meant to be directly referenced by the project and others are just supporting those DLLs and aren't meant for direct interaction. I know how to add files to be project references for NuGet: put them in the lib folder. But how do I get DLLs to be around to get picked up during builds but not be project references?
pranavkm on the NuGet CodePlex discussions pointed me here:
http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Explicit_Assembly_References
Related
I want to publish a dotnetcore2.1 nuget package using dotnet pack and dotnet nuget push.
The package is a project in a solution that has a reference to another project in that solution.
I can't install the package because it can't resolve the referenced project.
I tried doing this, and it includes the referenced package .dll to the .nupkg file, but it's still not possible to install it.
I can't really figure out what is the 'expected' way to do this. I definitely don't intend to publish the referenced project to the nuget feed.
Is this a massive oversight by microsoft or am I not getting something?
You have a project A that you want to pack and this project references another project B that is not usable or not intended for use on its own, but from a design perspective it is reasonable to keep it separate for purposes like reuse. In the end the package for project A should also contain project B.
Indeed this is an issue tracked in the NuGet repository, issue 3891. In both this and your link to the corresponding .NET project issue there are some workaround involving MS Build, but there is no official support, yet.
As stated in the above issue, even Microsoft seems to be aware of this issue and simply creates packages for the referenced projects that are marked with
Please do not reference directly
I think that until project references are supported, the safest way is to do same, although it is not convenient. Workarounds may become obsolete or cause strange behavior. However, since your referenced project is only intended to be used in your main library, you could include it like this
<PackageReference Include="LLL.Client" Version="1.0.0" PrivateAssets="all"/>
This way, the package contents from your referenced project will only be included in your project and consumers of your main package will not be able to see them.
I am reviewing our TFS access code after we upgraded to VS 2017 and VSTS Online.
I found out from another question on this site that the recommended way to access the TFS libraries is via a NuGetPackage.
Great, that's surely better than referencing from the Team Explorer installation folder.
However, the NuGet package in question added over 45 references to my project.
I believe I am only using 4-6 of them.
I found this question which discussed the fact that the package files do not have to go into source control.
That's good to know.
However, the references have been added as "Copy Local" and so they are all currently being copied to my output directory. This has caused my application to more than treble in size. It just doesn't seem like good practice.
Do people usually just ignore this and trade off against the fact they are getting great dependency management?
Or manually remove the non-required references...? Do future updates put the references back?
Or have I incorrectly consumed the package in some way...?
There are a lot of NuGet questions on this site. I did search but please accept my apologies if this is a duplicate.
Do people usually just ignore this and trade off against the fact they are getting great dependency management?
Add all dependencies to the project is the default behavior of NuGet. At this moment, there is not such option so that we could choose some of those dependencies.
Although all dependencies are added to the project as "Copy Local", when we publish our application, we could exclude those unneeded dependencies by changing the Publish Status from Include (Auto) to Exclude:
In this case, those non-required references are not included into the application.
Or manually remove the non-required references...? Do future updates
put the references back?
Yes, you can manually remove those non-required references, but when you update the package next time, those removed references would be re-add again.
Besides, as you said, you are only using 4-6 of them. You can try to custom a nuget package only including those 4-6 references.
Create nuget package from dlls
Hope this helps.
I have 2 projects: A & B that I want to publish as NuGet Packages but I don't know how to develop efficiently in Visual Studio.
Solution 1
Project A
Project B - references Project A as NuGet reference
When I make a change to Project A that is needed in Project B do I have to publish Project A? Is there a way to get the project reference functionality during development? Maybe Project B shouldn't reference Project A via NuGet?
There must be a good way to handle this situation, no? I've reviewed the NuGet docs but I couldn't find anything. There must be docs/blogs/SO posts to read more about this... I'm struggling to come up w/ the right keywords.
You might want to look at this extension: NuGet Reference Switcher for Visual Studio 2017
This allows you to switch between NuGet packages and project references during development.
Check out this blog post: https://markheath.net/post/multiple-nuget-single-repo
Basically, dotnet pack handles this for you automatically. You use regular project references when developing.
There must be a good way to handle this situation, no?
The best solutions is that the project-to-project reference should be recommend when the referenced project is modified frequently, the nuget reference is more appropriate when share the reference project to others or publish it. Just like NuGet Reference Switcher doing.
For some more detailed info, you can check following thread:
nuget packages in local work
NuGet has many advantages as a package manager for the Microsoft
development platform, this does not mean that it is not flawed. Just
as you encountered, if the referenced project is modified frequently,
we have to rebuild it, build nuget, publish it for each modification.
That will bring a lot of boring work. To resolve this disadvantages,
the Project-to-project references should be a better way.
The
advantage of a project-to-project reference is that it creates a
dependency between the projects in the build system. The dependent
project will be built if it has changed since the last time the
referencing project was built. A file reference does not create a
build dependency, so it is possible to build the referencing project
without building the dependent project.
You could add following Post-build event command to pack your project after building.
"the nuget.exe path\nuget.exe" pack "project path\NuGetPackageLibrary.csproj" -OutputDirectory "Your target path"
When your build successful, the package in target path will be replaced by the latest version.
I have a solution in Visual Studio 2013 with more C# project files that have source code in common but are targeting for different platforms (.Net, WinRT, .Net Micro Framework and so on).
All the csproj files are under the same directory.
These projects use a Nuget package that is available for all the above platforms itself.
If I add this Nuget package for one of the project (ex. .Net), the package.config file is created and inside has reference to that target (ex. .Net). The package is downloaded in the packages folder.
If I try to add the same package but for a different target to another project in the solution, the UI tells me that the package is already installed. It's true because a package.config file is already there but I'd like to have the same package for a different target.
So my question is the following : how can I add the same Nuget package to all different projects but with different targets ?
Thanks,
Paolo
Unfortunately, I don't think NuGet supports your scenario.
NuGet expects the packages.config file to be in the same folder as the .csproj file. There should be a 1-to-1 relation between these files. You should create a separate folder for each project rather than keep all .csproj files in the same folder.
If you want to share code across multiple projects, the easiest way is to use the new Shared Project support in Visual Studio. Normally this only applies to Universal Projects, but there is an extension[1] that you can install that enables Shared Projects for all project types.
Simply create a new Shared Project. Add all you common code to it. Then in your platform specific projects, you can simply Add Shared Project Reference.
Since each project is now independent, NuGet will add the appropriate package.
Hope this helps. Good luck!
[1] Shared Project Reference Manager https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
I have been trying to use NuGet in a complex solution (with around 100 project files) and been struggling with updating the existing references (from a /ext/.. directory ) to that of official NuGet directory. As far as I understand we need to manually select the project files (from the PackagaManager GUI/Manage Assemblies) and update the references. This is cumbersome to know which project uses what out of 100 odd projects. Is there any way (built-in to nuget or any other workaround) to update assemblies to nuget directory without having to manually select projects?
This is not supported as yet and I've registered an issue under codeplex's nuget project.