-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PackageReference: Need control over the selection for individual .dlls #5986
Comments
@nkolev92 can you please take a look at this? |
@KirillOsenkov |
Not quite. In non-SDK-style projects, set the In SDK-style projects there's a similar property: I'm also looking for a way to copy some .dlls to output, but not others. For instance, https://www.nuget.org/packages/Microsoft.VisualStudio.Composition/15.3.38 - I want to copy Microsoft.VisualStudio.Composition.dll to output, but I don't want any of the satellite resource assemblies. I wasn't able to find a way to do that. |
Also with PrivateAssets the problem is that I do want a reference to the .dll added to my project, but not copied to output. With CopyNuGetImplementations=false I can just rely on the inherited transitive package references. However to use PrivateAssets I need to duplicate the PackageReferences from ProjectA in ProjectB, which defeats the purpose of transitivity. |
ExcludeAssets=runtime does that, but it will apply to every dll in the lib folder |
Clear. |
Does @rohit21agrawal's proposal help? (excludeassets runtime) |
Nope, not quite, see my description above. |
Interesting, I think I'm after the opposite (roslyn 22095) where transitive .net DLLs are copied to output, but not included as references (or at least their APIs are not exposed). |
Very needed, to deal with not correctly configurated nugget packages. For example, for now
But in WinForms we absolutely no need of |
I've found that you can manually control which .dlls to reference and which .dlls to copy to output from a NuGet package if you turn off all assets on the PackageReference:
and then manually reference the .dlls you need:
Note the usage of |
@KirillOsenkov very cool workaround - thank you! I see here only 3 drawback:
|
This make it difficult to build an actual plugins with more than one level (transitive) reference instead of just sample like https://github.com/dotnet/samples/tree/main/core/extensions/AppWithPlugin, without manually or write an tools to remove duplicate assembly files and maybe also rewrite For example, Plugin.Host <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.1" PrivateAssets="all" />
</ItemGroup>
</Project> Plugin.Shared1 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.1" ExcludeAssets="runtime" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Plugin.Host\Plugin.Host.csproj" Private="False">
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
</Project> Plugin.Plugin1 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Plugin.Host\Plugin.Host.csproj" Private="False">
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\Plugin.Shared1\Plugin.Shared1.csproj" />
</ItemGroup>
</Project> |
I had the same issue packaging a single file executable, unnecessary transitive dependencies were bloating the package size. Enabling trimming broke the exe in strange ways, so I came up with this manual hack to remove files from the package prior to packaging. <Target Name="CleanupTransientDependencies" AfterTargets="PrepareForBundle">
<Message Text="CleanupTransientDependencies..." Importance="high" />
<!--<Message Text=" PRE: @(FilesToBundle)" Importance="high" /> -->
<ItemGroup>
<!-- Remove unused transient dependencies from the self-contained exe to reduce it's size. -->
<FilesToBundle Remove="@(FilesToBundle)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('%(FilesToBundle.Identity)', 'FileName.To.Remove.dll'))" />
</ItemGroup>
<!--<Message Text="POST: @(FilesToBundle)" Importance="high" /> -->
</Target> |
I recently ran into a similar issue (a package using an optional transitive dependency that causes my project to fail compilation due to a class/namespace conflict), and found #5986 (comment) as suitable workaround. However: I had to adjust the code slightly, because the build would should "Cannot find reference 'path/to/referenced.dll'" warnings that didn't affect compilation: <PackageReference Include="Foo.MyPackage" Version="1.0.0" ExcludeAssets="all" GeneratePathProperty="true" />
<Reference Include="CopyThis">
<HintPath>$(PkgFoo_MyPackage)\lib\net45\CopyThis.dll</HintPath>
<Private>true</Private>
</Reference> I wasn't really able to get this to work in any other way (using
For both cases, I obviously also want them to end up in the output directory when they're necessary at runtime (which is a must, because things wont work otherwise); or exclude them if they're not (which is a may; and I don't mind if they're there anyways). |
I have a slightly different scenario that requires this. Now I'd like to replace the transitive dependency A with a project reference to A instead. If I add A as a project reference and B as a nuget reference, I get assemblies from both the package transitively and project reference of A. I want to have project B just completely ignore its A dependency as if it wasn't there, so I don't get library, contentfiles and build.props conflicts. |
@dotMorten That scenario sounds more like dotnet/sdk#1151 |
Details about Problem
NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):
MSBuild 15.3 elements.
VS version (if appropriate):
15.3 or newer
Detailed repro steps so we can see the same problem
I don't see a way to control whether the .dll from PackageReference gets copied to output or not.
Additionally, if I have ProjectA with a PackageReference, and ProjectB referencing ProjectA, I want to make sure that when ProjectB builds, the .dll inherited transitively from ProjectA doesn't get copied to output (but I want it to get copied for ProjectA, and they have different output directories).
There needs to be a way to control this.
The text was updated successfully, but these errors were encountered: