0

I have following project structure with 3 Nuget dependencies:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net45;net46</TargetFrameworks>
    ...
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NUnit" Version="3.9.0" />
    <PackageReference Include="Selenium.WebDriver" Version="3.7.0" />
    <PackageReference Include="SpecFlow.CustomPlugin" Version="2.2.1" />
  </ItemGroup>

</Project>

It's really cool that VS2017 allows creating NuGet packages out of the box.

But what can do if I want to include custom NuGet references and don't wanna include references I use now?

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    ...
    <dependencies>
      <dependency id="SpecFlow" version="2.2.0" />
      <dependency id="NUnit" version="3.0.0" />
      <dependency id="Autofac" version="[3.3.0,3.5.2]" />
      <dependency id="Autofac.Configuration" version="[3.3.0]" />
      <dependency id="Selenium.WebDriver" version="3.0.0" />
    </dependencies>
  </metadata>
</package>

I this case I need to have Autofac with my lib but I don't need it to build my lib. Or I don't need SpecFlow.CustomPlugin with all dependencies in project which will use my lib but it needs have one to build itself.

I think there is a way to include NuSpec file path to new csproj but I think all csproj PropertyGroup fields won't be used.

Any suggestions? Thanks

unickq
  • 1,497
  • 12
  • 18

1 Answers1

0

You should use ExcludeAsset property following official documentation

https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files

I modified the exemple in doc to match with your needs. You can change the ExcludeAssets property if my change is not correct.

<ItemGroup>
    <!-- ... -->

    <PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
        <ExcludeAssets>build</ExcludeAssets>

    </PackageReference>

    <!-- ... -->
</ItemGroup>

EDIT :

I think you can try something like :

<PackageReference Include="Autofac" Version="3.5.2">
        <ExcludeAssets>build</ExcludeAssets>
  </PackageReference>
<PackageReference Include="Autofac.Configuration" Version="3.3.0">
        <ExcludeAssets>build</ExcludeAssets>
  </PackageReference>

If I well understand the documentation, this will exclude Props and targets in the build folder that are used to create by nuget package to create the dependencies

OrcusZ
  • 3,555
  • 2
  • 31
  • 48
  • Thanks for the link - still haven't figured out how to deal with it. Can you please post a config sample from my code when you have time? Thanks – unickq Dec 01 '17 at 08:38