-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add conflict resolution #1052
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
Add conflict resolution #1052
Conversation
Copied from dotnet/standard repo, commit a6be13f
…e other conflict resolution tests to cover more packages
4dbddc2
to
5d4ecd8
Compare
…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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 --> |
There was a problem hiding this comment.
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)' != ''"> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"?> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)"> |
There was a problem hiding this comment.
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
…n't do it if assets file doesn't exist
d45ca29
to
0157d3f
Compare
8f7848e
to
0937875
Compare
|
||
void Conflicts_are_resolved_when_publishing(bool selfContained, [CallerMemberName] string callingMethod = "") | ||
{ | ||
var targetFramework = "netcoreapp2.0"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" ?> |
There was a problem hiding this comment.
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)" /> |
There was a problem hiding this comment.
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>"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
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)"> |
There was a problem hiding this comment.
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)"> |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think these "handle conflicts" targets are implementation details, and shouldn't be part of our public API.
- Generating the deps file isn't an implementation detail. The deps file is a user artifact.
- 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.
There was a problem hiding this comment.
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:
- 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.
- 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.
- 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).
- 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.
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 |
@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 --> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
The AllCopyLocalItems has the Path metadata set to the path of the file within the package, not the target path it will be copied to
… to avoid conflicts with the version from Microsoft.Packaging.Tools
…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
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.