Repository navigation
Generate MSBuild property that has the path to a package #2271
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
Changes from all commits
2780650
9812847
625a3e7
ea9e4e9
a79668e
7a4a6e5
6c25a6e
fb2ff59
91b5532
fcbec73
668989d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -508,6 +508,8 @@ private static LibraryDependency ToPackageLibraryDependency(IVsReferenceItem ite | |
|
|
||
| // Mark packages coming from the SDK as AutoReferenced | ||
| AutoReferenced = GetPropertyBoolOrFalse(item, "IsImplicitlyDefined"), | ||
|
|
||
| GeneratePathProperty = GetPropertyBoolOrFalse(item, "GeneratePathProperty") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also create NET core sdk team to pass this new property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you mentioned this is a metadata, so you can ignore this comment. |
||
| }; | ||
|
|
||
| // Add warning suppressions | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,6 +426,8 @@ public static List<MSBuildOutputFile> GetMSBuildOutputFiles(PackageSpec project, | |
| var ridlessTargets = assetsFile.Targets | ||
| .Where(e => string.IsNullOrEmpty(e.RuntimeIdentifier)); | ||
|
|
||
| var packagesWithTools = new HashSet<string>(assetsFile.Libraries.Where(i => i.HasTools).Select(i => i.Name)); | ||
|
|
||
| foreach (var ridlessTarget in ridlessTargets) | ||
| { | ||
| // There could be multiple string matches from the MSBuild project. | ||
|
|
@@ -493,6 +495,31 @@ public static List<MSBuildOutputFile> GetMSBuildOutputFiles(PackageSpec project, | |
|
|
||
| props.AddRange(GenerateGroupsWithConditions(buildPropsGroup, isMultiTargeting, frameworkConditions)); | ||
|
|
||
| // Create an empty PropertyGroup for package properties | ||
| var packagePathsPropertyGroup = MSBuildRestoreItemGroup.Create("PropertyGroup", Enumerable.Empty<XElement>(), 1000, isMultiTargeting ? frameworkConditions : Enumerable.Empty<string>()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything preventing you from using the same pattern as the build props code?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is a little different in that its a property group with conditions vs an import group with no conditions containing imports with conditions. But if you feel strongly I can try to follow a pattern There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I understand correctly but we already add PropertyGroup with condition in nuget.g.props file. wouldn't this be similar to that? We can have a dict of packages path and add them in one shot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are you adding PropertyGroup condition for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are added on line |
||
|
|
||
| var projectGraph = targetGraph.Graphs.FirstOrDefault(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the flattened graph?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under the debugger, I found that the first graph was the project itself which has its direct dependencies. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure if that's the right statement, I'd double check it. Or filter it based on |
||
|
|
||
| // Distinct union of tool packages and packages with GeneratePathProperty=true | ||
| var packageIdsToCreatePropertiesFor = packagesWithTools.Union(projectGraph.Item.Data.Dependencies.Where(i => i.GeneratePathProperty).Select(i => i.Name)).Distinct(StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| var localPackages = sortedPackages.Select(e => e.Value); | ||
|
|
||
| // Find the packages with matching IDs in the list of sorted packages, filtering out ones that there was no match for or that don't exist | ||
| var packagePathProperties = localPackages | ||
| .Where(pkg => pkg?.Value?.Package != null && packageIdsToCreatePropertiesFor.Contains(pkg.Value.Package.Id) && pkg.Exists()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hit a case-sensitivity issue here. I believe this contains call is the cause since I don't see how it handles if the winner of the distinct call above had different case than the value in Package.Id.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I've hit this too but wasn't able to figure out the problem. I think you're right that its casing. I'll submit a PR |
||
| .Select(pkg => pkg.Value.Package) | ||
| // Get the property | ||
| .Select(GeneratePackagePathProperty); | ||
|
|
||
| packagePathsPropertyGroup.Items.AddRange(packagePathProperties); | ||
|
|
||
| // Don't bother adding the PropertyGroup if there were no properties added | ||
| if (packagePathsPropertyGroup.Items.Any()) | ||
| { | ||
| props.Add(packagePathsPropertyGroup); | ||
| } | ||
|
|
||
| if (isMultiTargeting) | ||
| { | ||
| // buildMultiTargeting/ {packageId}.targets | ||
|
|
@@ -720,5 +747,10 @@ private static HashSet<PackageDependencyInfo> ConvertToPackageDependencyInfo( | |
|
|
||
| return result; | ||
| } | ||
|
|
||
| private static XElement GeneratePackagePathProperty(LocalPackageInfo localPackageInfo) | ||
| { | ||
| return GenerateProperty($"Pkg{localPackageInfo.Id.Replace(".", "_")}", localPackageInfo.ExpandedPath); | ||
| } | ||
| } | ||
| } | ||
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 also need to update
_referenceMetadatain order to populatereferenceinstance withGeneratePathPropertymetadata.And please add tests to consume this property inside VS for PackageReference based projects (both SDK/ classic csproj), otherwise we might end up in broken state for commandLine vs VS.
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.
Done. I don't see anywhere that your tests are verifying that PackageReference metadata is read correctly in Visual Studio. Where should I add these tests?
I found LegacyPackageReferenceProjectTests but it doesn't seem related to
VsManagedLanguagesProjectSystemServicesIs
VsManagedLanguagesProjectSystemServicespulled into a test via MEF and I can't find 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.
You'll have to add End-to-end tests (Apex Tests) to cover this scenario inside Visual Studio. May be @nkolev92 can help you with that...
I'm also adding func tests for
LegacyPackageReferenceProjectwhich should add the relevant infrastructure to test these projects inside VS but that will also mockVsManagedLanguagesProjectSystemServicessince it calls into Project System.