Skip to content

Conversation

dsplaisted
Copy link
Member

@dsplaisted dsplaisted commented Mar 29, 2017

Fixes #974. Currently work in progress, see the issue for what's done and what's left to do.

EDIT: This should now be ready for review.

@dsplaisted dsplaisted force-pushed the resolve-conflicts-974 branch from 4dbddc2 to 5d4ecd8 Compare April 3, 2017 23:55
…e on disk

This avoids conflicts being reported in log files when the same FrameworkAssembly reference is declared in multiple NuGet packages

namespace Microsoft.NET.Build.Tasks.ConflictResolution
{
public partial class RemoveDepsFileConflicts : Task
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this was in your plan or not, but instead of generating everything into the .deps.json file, and then removing the conflicts in a separate task, we should just be feeding the Conflicts into the original GenerateDepsFile task. Then we can generate the whole thing in one shot.

It makes the logic simpler, and more efficient.

@@ -0,0 +1,133 @@
<!--
***********************************************************************************************
Microsoft.Packaging.Tools.targets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best file name for this targets file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in fact it must be changed.

</PropertyGroup>
</When>
<Otherwise>
<!-- NuGet 2, run before targets that consume references -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to handle NuGet 2 or 3. We will only ever support the NuGet we are using.

<!-- Allow completely disabling the conflict resolution targets-->
<When Condition="'$(DisableHandlePackageFileConflicts)' == 'true'" />
<!-- Condition here is a hack until https://github.com/dotnet/sdk/issues/534 is fixed -->
<When Condition="'$(TargetFramework)' != '' or '$(TargetFrameworks)' != ''">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this condition/hack. We obviously know that the project is using this SDK, because this file is being loaded from our SDK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing we need is a good property to understand when the SDK is providing this so that we can use the version from the standard repo in that case (nuget2/nuget3).

@@ -0,0 +1,148 @@
#Dependency Trimming
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my understanding that trimming was not a 2.0 feature. Should this be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are leaving it in, we should have tests for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be brought up. @dsplaisted as we mentioned before the trimming stuff should be left in standard repo. Just make sure you are able to support the same sort of hook it requires, which is the same as conflict resolution: items to exclude from copy to output by build and publish and exclude from deps file.

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this file nor the .builds file.

All these targets and tasks should just come with our SDK just like any other targets and task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor the CSProj. I'd expect this all to be added to your existing project.


namespace Microsoft.NET.Build.Tasks
{
internal class LockFileCache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this file in our SDK. This can be removed.

TargetFramework="$(TargetFrameworkMoniker)"
RuntimeIdentifier="$(RuntimeIdentifier)"
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
PrivateAssetsPackageReferences="@(PrivateAssetsPackageReference)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs the change I made here: https://github.com/dotnet/standard/pull/283/files

@dsplaisted dsplaisted force-pushed the resolve-conflicts-974 branch from d45ca29 to 0157d3f Compare April 4, 2017 15:15
@dsplaisted dsplaisted force-pushed the resolve-conflicts-974 branch from 8f7848e to 0937875 Compare April 4, 2017 15:39

void Conflicts_are_resolved_when_publishing(bool selfContained, [CallerMemberName] string callingMethod = "")
{
var targetFramework = "netcoreapp2.0";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to also test "low fat apps" as well. See #1053.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried adding a test for this, and it's getting a bunch of DLLs in the output that shouldn't be copied there. I think it's because the version of the Microsoft.NETCore.App package that we're using (2.0.0-beta-001834-00) has this logic in it:

  <ItemGroup Condition="'$(RuntimeIdentifier)' == ''">
    <PackageConflictPlatformManifests Include="$(MSBuildThisFileDirectory)Microsoft.NETCore.App.PlatformManifest.txt" />
  </ItemGroup>

So the platform manifest isn't getting picked up for rid-specific shared framework apps. Has this been updated in newer versions of the package? What version would have a fix?

@eerhardt @ericstj @weshaggard

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made a fix for that. dotnet/core-setup#1936

That fix is in 2.0.0-preview1-001913-00.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That build is working its way into the CLI now. @dotnet-bot should be updating dotnet/cli#6238 with the 1913 version soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsplaisted - there is a new CLI build that contains this fix:

2.0.0-preview1-005722

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8" ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not copy this...

</PropertyGroup>
<Target Name="RemovePublishDepsFileConflicts" AfterTargets="$(RemovePublishDepsFileConflictsAfter)"
Inputs="$(PublishDepsFilePath)" Outputs="$(_RemovePublishDepsFileConflictsSemaphore)">
<RemoveDepsFileConflicts DepsFilePath="$(PublishDepsFilePath)" Conflicts="@(_ConflictPackageFiles);@(_PublishConflictPackageFiles)" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to kill this target and task and add the proper support into to deps file generation to provide a list of things to omit.

<dependency id=""System.Threading.Timer"" version=""4.3.0"" />
<dependency id=""System.Xml.ReaderWriter"" version=""4.3.0"" />
<dependency id=""System.Xml.XDocument"" version=""4.3.0"" />
</group>";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hard-code xml here just to parse it below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a copy/paste from the .nuspec. It seems less error prone (and easier) to just leave it in that form.

public ITaskItem[] ReferenceSatellitePaths { get; set; }

[Required]
public ITaskItem[] FilesToSkip { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a test that verifies the .deps.json file is trimmed correctly. I don't see one. It could probably go into Microsfot.NET.Build.Tests

TargetFramework="$(TargetFrameworkMoniker)"
RuntimeIdentifier=""
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
PrivateAssetsPackageReferences="@(PrivateAssetsPackageReference)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pass in $(IsSelfContained)

<HandlePackageFileConflictsDependsOn Condition="'$(SelfContained)' != 'true'">_GetLockFileAssemblies</HandlePackageFileConflictsDependsOn>
</PropertyGroup>

<Target Name="HandlePackageFileConflicts" AfterTargets="ResolvePackageDependenciesForBuild" DependsOnTargets="$(HandlePackageFileConflictsDependsOn)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want these "Conflicts" Targets to be part of our "public API"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, we should prefix the name with "_".


In reply to: 110262316 [](ancestors = 110262316)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it seems to be on the same level as other targets (eg for generating the deps files) that we define.

"Public API" or not I think it's OK to change these if we need to- ie I don't think we need to guarantee compatibility across versions of the SDK for targets that plug into our SDK.

Copy link
Member

@eerhardt eerhardt Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think these "handle conflicts" targets are implementation details, and shouldn't be part of our public API.
  2. Generating the deps file isn't an implementation detail. The deps file is a user artifact.
  3. I think we need to have an "all up" extension story on what we think we can and can't change across versions of the SDK. The current approach has been to prefix "private" things with _. If that is changing here, we should document it somehow to let people know what our extension story is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think folks will depend on doing stuff after these, so we have to imagine an extension point for "where do I sequence a target to get a filtered list of reference/referencecopylocalpaths/deps-file-items.

I agree with @eerhardt that these should not be public.

They should also not occupying the "good spot" for sequencing. What I mean here is that folks should easily be able to run after them without having ambiguous ordering with these targets themselves.

The names/sequencing they have now are due to me implementing them outside the SDK. Inside the SDK I think they should be rolled into other target sequences.

Here's a straw man:

  1. As a dev extending the SDK I can sequence a target AfterTargets="ResolveReferences" and I am garunteed to get a complete and filtered list of Reference and ReferencePath items.
  2. As a dev extending the SDK I can sequence a target AfterTargets="ResolvePackageDependenciesForBuild" and I am garunteed to get a complete and filtered list of items used to construct the build-time deps file.
  3. As a dev extending the SDK I can sequence a target AfterTargets="RunResolvePublishAssemblies" and I am garunteed to get a complete and filtered list of ResolvedAssembliesToPublish items (not the case today).
  4. As a dev extending the SDK I can sequence a target AfterTargets="ComputeFilesToPublish" and I am garunteed to get a complete and filtered list of ResolvedFileToPublish items, as well as a complete and filtered set of items that will be used to construct the deps file.

Perhaps 1 & 2 and 3 & 4 can be collapsed so long as the items output don't have a relationship (eg one copied to the other).

Moreover, we should have a property that folks can append Targets to so that folks that want to hook this sequence can insert themselves into a deterministic sequence and follow a pattern with common inputs/outputs (a specific set of items) that they can operate on and garuntee those items are the only thing they need to care about updating.

@dsplaisted
Copy link
Member Author

@eerhardt @ericstj I've addressed the feedback, and added some tests for the deps.json

@dsplaisted
Copy link
Member Author

I've added tests for running an app from the output folder. As @ericstj suspected, running from the output folder when a RID was specified and there were conflicts on runtime items was broken.

I resolved this by switching from using the ResolvePublishAssemblies task in _GetLockFileAssemblies to depending on ComputePrivateAssetsPackageReferences, which gets the files that will be copied to the output folder if CopyLocalLockFileAssemblies is set. This uses the items from the assets file that flow through MSBuild like we have discussed. I don't know that the resulting items will be exactly the same as would come from ResolvePublishAssemblies, but I think that if there are differences it would be that the publish resolver excludes publishing certain files, which we may not want to exclude from conflict resolution anyway.

@dsplaisted
Copy link
Member Author

@dotnet-bot test Windows_NT_FullFramework Debug

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>

<!-- This property disables the conflict resolution logic from the Microsoft.Packaging.Tools package, which is superceded by the logic here in the SDK -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the Packaging.Tools package will change to not be enabled for SDK projects, and then this property can just go away. Do we have a bug logged to track that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've filed dotnet/standard#298


<Target Name="_GetLockFileAssemblies"
DependsOnTargets="_ComputeLockFileCopyLocal">
<!-- We need to find all the files that will be loaded from deps for conflict resolution.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better. Any reason you didn't use @(AllCopyLocalItems)? Those look like they'll have the NuGetPackageId metadata which HandlePackageFileConflicts depends on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably eliminate this as a separate target entirely and just have HandlePackageFileConflicts depend on _ComputeLockFileCopyLocal.

@dsplaisted dsplaisted merged commit 1d81050 into dotnet:master Apr 11, 2017
@dsplaisted dsplaisted deleted the resolve-conflicts-974 branch April 12, 2017 00:45
mmitche pushed a commit to mmitche/sdk that referenced this pull request Jun 5, 2020
…0191030.9 (dotnet#1052)

- Microsoft.AspNetCore.Analyzers - 3.1.0-preview3.19530.9
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.1.0-preview3.19530.9
- Microsoft.AspNetCore.Mvc.Analyzers - 3.1.0-preview3.19530.9
- Microsoft.AspNetCore.Components.Analyzers - 3.1.0-preview3.19530.9
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

Successfully merging this pull request may close these issues.

7 participants