Skip to content
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

Filtering CopyLocalLockFileAssemblies #933

Closed
nguerrera opened this issue Mar 3, 2017 · 5 comments
Closed

Filtering CopyLocalLockFileAssemblies #933

nguerrera opened this issue Mar 3, 2017 · 5 comments
Assignees
Milestone

Comments

@nguerrera
Copy link
Contributor

nguerrera commented Mar 3, 2017

When you use CopyLocalLockFileAssemblies with a netcoreapp project, it copies shared framework assets too.

While you can use publish instead to copy without those assemblies, there are circumstances where its more practical and efficient to just have the single build step. In particular pack is driven by build output not publish output. Consider the case where I want to flatten dependencies in a nupkg (e.g. as currently required to package msbuild tasks).

One way to address this would be to just have a flag to apply the same filtering as publish to CopyLocalLockFileAssemblies.

Alternatively, I find myself wishing that I could just slap metadata on my package references to exclude their full closure from CopyLocal. ExcludeAssets=Runtime almost works, but if I have another sibling package that pulls in overlapping assets in its closure, they get re-included.

In the msbuild task scenario, I really want to say "copy everything that is not in the closure of Microsoft.NETCore.App, Microsoft.Build.Framework, or Microsoft.Build.Utilities.Core"

I managed to get close enough to that with this workaround:

<PropertyGroup>
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Microsoft.Build.Framework" Version="15.1.548" ExcludeAssets="Runtime" />
  <PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.548" ExcludeAssets="Runtime" />
</ItemGroup>

<!-- Remove files from copy local that would not be published as they are provided by the platform package -->
<Target Name="FilterCopyLocal" DependsOnTargets="RunResolvePublishAssemblies" BeforeTargets="ResolveLockFileCopyLocalProjectDeps">
  <ItemGroup>
    <_CopyLocalButNotPublished Include="@(AllCopyLocalItems)" Exclude="@(ResolvedAssembliesToPublish)" />
    <AllCopyLocalItems Remove="@(_CopyLocalButNotPublished)" />
  </ItemGroup>
</Target>
@dsplaisted
Copy link
Member

As noted in dsplaisted@13989f1, it is now necessary for FilterCopyLocal to depend on PrepareForBuild;RunResolvePublishAssemblies.

The reason for this is that with #1618, conflict resolution now depends on TargetFrameworkDirectory property, and the GetReferenceAssemblyPaths target to set it. However, the custom FilterCopyLocal target in our projects was causing GetReferenceAssemblyPaths to run before GetFrameworkPaths, and when GetFrameworkPaths was subsequently run, it reset the TargetFrameworkDirectory property to v4.0.30319.

@peterhuene peterhuene self-assigned this Oct 24, 2018
@peterhuene peterhuene modified the milestones: 2.3.0, 3.0.1xx Oct 24, 2018
peterhuene pushed a commit to peterhuene/sdk that referenced this issue Nov 6, 2018
This commit implements some of the unification of the `dotnet build` and
`dotnet publish` experiences.

For 3.0 targeted projects, `dotnet build` will now copy the package
dependencies locally into the output directory instead of relying on the NuGet
cache.  It behaves the same as `dotnet publish`, only copying what is not
provided by the shared frameworks.

Additionally, `dotnet publish` will now copy the build outputs rather than
regenerating a deps file or resolving package dependencies, provided there are
no package references excluded from publishing or packages are coming from a
runtime store.

The `CopyLocalLockFileAssemblies` property can be set to `false` to revert to
the previous behavior for `dotnet build`.

Fixes dotnet/cli#10061.
Fixes dotnet#933.
peterhuene pushed a commit to peterhuene/sdk that referenced this issue Nov 13, 2018
This commit implements some of the unification of the `dotnet build` and
`dotnet publish` experiences.

For 3.0 targeted projects, `dotnet build` will now copy the package
dependencies locally into the output directory instead of relying on the NuGet
cache.  It behaves the same as `dotnet publish`, only copying what is not
provided by the shared frameworks.

Additionally, `dotnet publish` will now copy the build outputs rather than
regenerating a deps file or resolving package dependencies, provided there are
no package references excluded from publishing or packages are coming from a
runtime store.

The `CopyLocalLockFileAssemblies` property can be set to `false` to revert to
the previous behavior for `dotnet build`.

Fixes dotnet/cli#10061.
Fixes dotnet#933.
peterhuene pushed a commit to peterhuene/sdk that referenced this issue Nov 13, 2018
This commit implements some of the unification of the `dotnet build` and
`dotnet publish` experiences.

For 3.0 targeted projects, `dotnet build` will now copy the package
dependencies locally into the output directory instead of relying on the NuGet
cache.  It behaves the same as `dotnet publish`, only copying what is not
provided by the shared frameworks.

Additionally, `dotnet publish` will now copy the build outputs rather than
regenerating a deps file or resolving package dependencies, provided there are
no package references excluded from publishing or packages are coming from a
runtime store.

The `CopyLocalLockFileAssemblies` property can be set to `false` to revert to
the previous behavior for `dotnet build`.

Fixes dotnet/cli#10061.
Fixes dotnet#933.
collinsauve added a commit to collinsauve/AspNetCoreTest that referenced this issue Dec 31, 2018
@jzabroski
Copy link

@peterhuene Is the milestone on this issue correct? When/how can I take advantage of this?

@peterhuene
Copy link
Contributor

With a 3.0 SDK (including preview7 that came out today), we're now copying the assets locally for build like we would for a publish. It should happen automatically (can be opted out of with setting CopyLocalLockFileAssemblies to false).

@Seabizkit
Copy link

@nguerrera

there are a lot of word... are you saying when u use true
it would copy the dependencies locally...

But let say A had a B dependency now B had C

but now you say

<ProjectReference Include="B">
	<Private>false</Private>
	<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

it still include C is this issue to correct this or at least provide away of saying if you ignore the parent ignore all the childern of that parent

@nguerrera
Copy link
Contributor Author

@Seabizkit I haven't worked on this in a long time and I've forgotten all the details. I think you might be better off filing a new issue describing what you want to achieve and what is stopping you so that the current team can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants