0

Using .NET Core, I'm trying to create a new Nuget without it installing the it's own dependencies. This is my new NuGet package csproj:

 <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup Label="Globals">
    <TargetFrameworks>net461</TargetFrameworks>
    <PackageId>MyFirstNuget</PackageId>
    <Version>1.0.1-prerelease</Version>
    <Authors></Authors>
    <Company></Company>
    <Description></Description>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <SccLocalPath>.</SccLocalPath>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="SomePackage" Version="7.12.4" />
  </ItemGroup>
</Project>

When I install the package on a project it installs the package "SomePackage" example

Is there an option not to install all the dependencies?

2 Answers 2

3

When working with PackageReference there are some ways to control dependency assets.

As stated here:

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

In your case you need to use PrivateAssets like this:

 <ItemGroup>
    <PackageReference Include="SomePackage" Version="7.12.4">
       <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

since your project uses SomePackage, but you don't want SomePackage installed when you use your new NuGet package.

Sign up to request clarification or add additional context in comments.

Comments

1

I think PrivateAssets can help you. Try changing your PackageReference to

<PackageReference Include="UmbracoCms" Version="7.12.4">
  <PrivateAssets>all</PrivateAssets>
</PackageReference>

4 Comments

It still installs all the files
Sorry, I don't understand your original question very well. Do you want to remove UmbracoCms content from your project? Or do you want UmbracoCms to not be a dependency of your package, so when someone else installs your package, they do not get UmbracoCms?
I have project that include nuget like UmbracoCms when I do build I don't want to see the files (I don't want that install the UmbracoCms into the project that include the nugets) only when I install the *.nupkg file (example other project) I want to see the file for umbraco
ok, I think <ExcludeAssets>content;contentFiles</ExcludeAssets> is what you want, but I'm really sorry, I have trouble understanding your messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.