.NET Core: how to exclude NuGet libs from output - visual-studio

I have a project with Protobuf files that uses the simple server of Grpc.Core, not the ASP.NET Core Kestrel of IIS server. To compile the proto-files nicely with Visual Studio, you need to install the NuGet Grpc.AspNetCore in the project. However, I don't wan't them to be copied to the output directory because they are not needed. Of course I can delete them in a post-build step but that's a hack. You can mark the NuGet package as "Private Assets all" but that doesn't work. The dlls still appear in the output bin.
Does anybody know how to do the trick?

From NuGet's docs
IncludeAssets
These assets will be consumed
ExcludeAssets
These assets will not be consumed
PrivateAssets
These assets will be consumed but won't flow to the parent project
so, you could try PrivateAssets="all" ExcludeAssets="runtime".

Related

Difference in nugets processing via `dotnet add package ..` vs nugets adding via visual studio UI

I need to use native c libraries in my library(that supports several Core TFs and .net framework) which is published via nuget. I configured it via .csproj file and runtimes folder. But I noticed that when I consume my NuGet via dotnet add package .. in some cases, the native libraries are not copied into the expected folder after consuming, however when I use the VS UI Nuget package manager->Manage Nuget Packages for Solution, all files are placed into correct places.
So, I assume that Nuget package manager makes more steps than just call dotnet add package .., but it's unclear what exactly happens, any help will be appreciated.
Actually, dotnet add package does the same effect as Nuget package manager UI in VS IDE. They simply install a Nuget package into your project and there is no difference. No additional operations will be performed. Like add some xml node in
So I think there is something else wrong in your project.
Please check under tips to troubleshoot your issue:
1) clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages.
2) And if the runtimes folder does not exist under your project, I think it is controlled by dependency assets. Like ExcludeAssets=runtime or native. It will prevent the function of runtimes folder. Please see this official document.
So after you finishing installing the nuget package, you should check your csproj file, and make sure that there is no such like
<ExcludeAssets>runtime;native</ExcludeAssets>
under PackageReference node.
If there is any this node, please delete it.
3) delete bin and obj folder. Then rebuild your project to test again. Or if you use dotnet command line, you should additionally add dotnet build command. In my side, I run dotnet build -p:platform=xxx;Configuration=Release.

Nuget Packages not installing anything in .net core app

I am trying to install knockoutjs and typescript in a .net core app via Nuget.
It shows in Packages but doesn't install anything in a scripts folder as has previously in asp.net.
What am I missing?
TL;DR ASP.NET Core no longer works in that way (packages copying javascript/css content into your project). You need to adapt your workflow.
.NET Core projects only work in SDK-style projects, and SDK style projects only use NuGet's PackageReference, not packages.config. The docs on migrating from packages.config to PackageReference list one package compatibility issue as not supporting the content folder, which is how in packages.config those assets are copied into your project on package install.
I can't find a doc listing recommendations for ASP.NET Core apps, but my understanding is you can either use LibMan, or use NPM, which is in line with basically the rest of the web development industry outside of .NET has been doing. If you use the new project templates to create a new ASP.NET Core Angular or ASP.NET Core React app, you'll see they create a ClientApp folder that uses npm and all the official react/angular CLI tools. The MVC template has copies of jQuery and bootstrap, without an obvious way how to update them.
might be some unsync, remove the packages folder from the solution and restore the packages again. It will fix the issue. Also check the output window, that will show the list of errors.
It shows in Packages but doesn't install anything in a scripts folder
as has previously in asp.net.
First, I agree with zivkan. It is a feature of PackageReference Nuget Management format.
VS has two format to manage nuget packages: Packages.config and PackageReference.
Since new sdk format projects(Net Core and Net Standard) only use PackageReference to manage nuget packages,it will be very different from the effect reflected by the packages.config package management format.
When you use Content files from the nuget packages with PackageReference, it will lose files from the Scripts folder.
Just as this document said, it has such compatibility issues.
Actually, you can enter C:\Users\xxxx\.nuget\packages\knockoutjs\3.5.1 and find there is a folder called Content, Nuget will copy the content of that folder into your project when you install this nuget package.
But Content folder can be recognized by Packages.config format, and as far as I know, ContentFiles folder is used in PackageReference to add the content into your project. So in your situation, the nuget package should include ContentFiles folder at the same time. See this official document.
But the knockoutjs nuget package does not have contentfiles folder. That is why net framework projects with packages.config has the content files while new sdk projects does not have it.
And this behavior change can only be effective when you create the nuget package, so you ca n’t make any kind of change, you can only contact the author of the package to make this modification, and let him add this function as soon as possible to apply to the new SDK format project.
Suggestion
So So for now, you can try these:
1) you can either manually Add the content file from C:\Users\xxxx\.nuget\packages\knockoutjs\xxxx\Content to the project by Adding Existing Items.
2) roll back to use Net Framework projects with packages.config.
3) contact with the author on this link.

How do I get my nuget packages copied to bin during a build for a asp.net website (not web app)?

Here's my setup. I have a classic .Net website, not web app. I have all my compiled objects in a self-hosted nuget repo. When I build in VS, it looks at my packages and copies the binaries to the bin folder but when I try and build in Azure DevOps it's not working. My Nugets restore just fine but I haven't hit on the right msbuild arguments to make it work. I know that .Net websites are not common these days. I found this (How to use NuGet packages with an ASP.NET Website on CI Server) which was a path I was considering (putting .refresh.dll files in source control) but it seems like there should be an easier way.
How do I get my nuget packages copied to bin during a build for a asp.net website (not web app)?
What you are considering (putting .refresh.dll files in source control) is the most appropriate way.
From here:
They are simple because if you view them in a text editor, you’ll see
they contain nothing more than the full path to the dll.
Turns out, these dll.refresh files are an exception to the rule, and
they should go into source control. Its the only way your web project
will know where its references live.
For building and package restore to work, you can keep the bin folder and any .refresh files. You can remove the other binaries from your version control system.
Hope this helps.

Perfered method for removing Roslyn folder from Octopus deploy nuget package

I've noticed that octopack is including the Roslyn folder under the bin folder for my web deployment. What would be the preferred method for excluding this from the build without affecting development. I considered a post build event in only the "release" solution config to delete it but wondered if there was a better way (and it doesn't need to be specific to octopus).
This folder is added by the Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget package. If you want C#6 support in Asp.Net (.cshtml or .aspx) files it needs to be there, because the roslyn's csc.exe from that folder is used to compile your views.
In order to be able to remove it (not deploy it), you'd need to precompile your web application with aspnet_compiler.exe

Dissociate files from Nuget without removing from the project

I have a project with a few front-end frameworks obtained via and managed by Nuget (Twitter Bootstrap, jQuery, jQuery UI ...).
I want to keep the files in my project, but remove them from Nuget's grip (I don't like the way Nuget organizes these files).
When I un-check the project for a library Nuget removes all the files it had installed, unless I've editted them (e.g. I over-wrote bootstrap.css with a customized version from getbootstrap.com).
As I do this from time-to-time, instead of backing up the /Content and /Scripts directories and adding back in the relevant files after removing the library from Nuget, I'd like to be able to dissociate all files of a particular library from Nuget at once without removing them from the project's directories. Is that possible, by either the GUI or the console?
I don't know if this issue is specific to a version(s) of Visual Studio, but mine is VS 2012
Can you elaborate for the part of "I don't like the way Nuget organizes these files"? If you remove NuGet from the picture, the good things that it does for you (detection of package updates, automatic package restore etc.) will be gone.
If you absolutely need to do this, one possible hack would be deleting packages.config from the project.

Resources