-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Updating GenerateDepsFile so that direct references of referenced projects appear in the deps.json #2090
Updating GenerateDepsFile so that direct references of referenced projects appear in the deps.json #2090
Changes from 4 commits
9b7041a
46ee3c6
d020c70
a153ad4
f4928e9
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ internal class DependencyContextBuilder | |
private readonly ProjectContext _projectContext; | ||
private IEnumerable<ReferenceInfo> _referenceAssemblies; | ||
private IEnumerable<ReferenceInfo> _directReferences; | ||
private IEnumerable<ReferenceInfo> _dependencyReferences; | ||
private Dictionary<string, SingleProjectInfo> _referenceProjectInfos; | ||
private IEnumerable<string> _excludeFromPublishPackageIds; | ||
private CompilationOptions _compilationOptions; | ||
|
@@ -97,6 +98,12 @@ public DependencyContextBuilder WithDirectReferences(IEnumerable<ReferenceInfo> | |
return this; | ||
} | ||
|
||
public DependencyContextBuilder WithDependencyReferences(IEnumerable<ReferenceInfo> dependencyReferences) | ||
{ | ||
_dependencyReferences = dependencyReferences; | ||
return this; | ||
} | ||
|
||
public DependencyContextBuilder WithReferenceProjectInfos(Dictionary<string, SingleProjectInfo> referenceProjectInfos) | ||
{ | ||
_referenceProjectInfos = referenceProjectInfos; | ||
|
@@ -161,7 +168,8 @@ public DependencyContext Build() | |
} | ||
runtimeLibraries = runtimeLibraries | ||
.Concat(GetLibraries(runtimeExports, libraryLookup, dependencyLookup, runtime: true).Cast<RuntimeLibrary>()) | ||
.Concat(GetDirectReferenceRuntimeLibraries()); | ||
.Concat(GetDirectReferenceRuntimeLibraries()) | ||
.Concat(GetDependencyReferenceRuntimeLibraries()); | ||
|
||
IEnumerable<CompilationLibrary> compilationLibraries = Enumerable.Empty<CompilationLibrary>(); | ||
if (includeCompilationLibraries) | ||
|
@@ -379,6 +387,20 @@ private Library GetLibrary( | |
else if (export.IsProject()) | ||
{ | ||
referenceProjectInfo = GetProjectInfo(library); | ||
|
||
if (runtime) | ||
{ | ||
// DependencyReferences do not get passed to the compilation, so we should only | ||
// process them will getting the runtime libraries. | ||
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. (nit) wording - 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. Fixed. |
||
|
||
foreach (var dependencyReference in referenceProjectInfo.DependencyReferences) | ||
{ | ||
libraryDependencies.Add( | ||
new Dependency( | ||
GetReferenceLibraryName(dependencyReference), | ||
dependencyReference.Version)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -530,9 +552,9 @@ private string ResolveFrameworkReferencePath(string fullPath) | |
return Path.GetFileName(fullPath); | ||
} | ||
|
||
private IEnumerable<RuntimeLibrary> GetDirectReferenceRuntimeLibraries() | ||
private IEnumerable<RuntimeLibrary> GetReferenceRuntimeLibraries(IEnumerable<ReferenceInfo> references) | ||
{ | ||
return _directReferences | ||
return references | ||
?.Select(r => CreateRuntimeLibrary( | ||
type: "reference", | ||
name: GetReferenceLibraryName(r), | ||
|
@@ -547,9 +569,9 @@ private IEnumerable<RuntimeLibrary> GetDirectReferenceRuntimeLibraries() | |
Enumerable.Empty<RuntimeLibrary>(); | ||
} | ||
|
||
private IEnumerable<CompilationLibrary> GetDirectReferenceCompilationLibraries() | ||
private IEnumerable<CompilationLibrary> GetReferenceCompilationLibraries(IEnumerable<ReferenceInfo> references) | ||
{ | ||
return _directReferences | ||
return references | ||
?.Select(r => new CompilationLibrary( | ||
type: "reference", | ||
name: GetReferenceLibraryName(r), | ||
|
@@ -562,6 +584,21 @@ private IEnumerable<CompilationLibrary> GetDirectReferenceCompilationLibraries() | |
Enumerable.Empty<CompilationLibrary>(); | ||
} | ||
|
||
private IEnumerable<RuntimeLibrary> GetDirectReferenceRuntimeLibraries() | ||
{ | ||
return GetReferenceRuntimeLibraries(_directReferences); | ||
} | ||
|
||
private IEnumerable<CompilationLibrary> GetDirectReferenceCompilationLibraries() | ||
{ | ||
return GetReferenceCompilationLibraries(_directReferences); | ||
} | ||
|
||
private IEnumerable<RuntimeLibrary> GetDependencyReferenceRuntimeLibraries() | ||
{ | ||
return GetReferenceRuntimeLibraries(_dependencyReferences); | ||
} | ||
|
||
private string GetReferenceLibraryName(ReferenceInfo reference) | ||
{ | ||
if (!ReferenceLibraryNames.TryGetValue(reference, out string name)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ public class GenerateDepsFile : TaskBase | |
[Required] | ||
public ITaskItem[] ReferencePaths { get; set; } | ||
|
||
[Required] | ||
public ITaskItem[] ReferenceDependencyPaths { get; set; } | ||
|
||
[Required] | ||
public ITaskItem[] ReferenceSatellitePaths { get; set; } | ||
|
||
|
@@ -112,16 +115,20 @@ protected override void ExecuteCore() | |
AssemblyName, | ||
AssemblyExtension, | ||
AssemblyVersion, | ||
AssemblySatelliteAssemblies); | ||
AssemblySatelliteAssemblies); | ||
|
||
IEnumerable<ReferenceInfo> referenceAssemblyInfos = | ||
ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies); | ||
|
||
IEnumerable<ReferenceInfo> directReferences = | ||
ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths); | ||
|
||
IEnumerable<ReferenceInfo> dependencyReferences = | ||
ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths); | ||
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. Does the satellite information for these 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. Yes. The Under the current code, the satellites are being adding to the project reference resources and the actual reference resources, so I'll need to fix up the logic slightly: "ClassLibrary1/1.0.0": {
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "4.4.0",
"ClassLibrary2": "1.0.0.0",
"ClassLibrary3": "1.0.0.0"
},
"runtime": {
"ClassLibrary1.dll": {}
},
"resources": {
"de-DE/ClassLibrary2.resources.dll": {
"locale": "de-DE"
},
"de-DE/ClassLibrary3.resources.dll": {
"locale": "de-DE"
}
}
},
"ClassLibrary2.Reference/1.0.0.0": {
"runtime": {
"ClassLibrary2.dll": {}
},
"resources": {
"de-DE/ClassLibrary2.resources.dll": {
"locale": "de-DE"
}
}
},
"ClassLibrary3.Reference/1.0.0.0": {
"runtime": {
"ClassLibrary3.dll": {}
},
"resources": {
"de-DE/ClassLibrary3.resources.dll": {
"locale": "de-DE"
}
}
} |
||
|
||
Dictionary<string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos( | ||
ReferencePaths, | ||
ReferenceDependencyPaths, | ||
ReferenceSatellitePaths); | ||
|
||
IEnumerable<string> excludeFromPublishAssets = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences); | ||
|
@@ -136,6 +143,7 @@ protected override void ExecuteCore() | |
.WithMainProjectInDepsFile(IncludeMainProject) | ||
.WithReferenceAssemblies(referenceAssemblyInfos) | ||
.WithDirectReferences(directReferences) | ||
.WithDependencyReferences(dependencyReferences) | ||
.WithReferenceProjectInfos(referenceProjects) | ||
.WithExcludeFromPublishAssets(excludeFromPublishAssets) | ||
.WithCompilationOptions(compilationOptions) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,10 +51,29 @@ public static IEnumerable<ReferenceInfo> CreateDirectReferenceInfos( | |
r.HasMetadataValue("ReferenceSourceTarget", "ResolveAssemblyReference") && | ||
string.IsNullOrEmpty(r.GetMetadata("NuGetSourceType"))); | ||
|
||
return CreateFilteredReferenceInfos(directReferencePaths, referenceSatellitePaths); | ||
} | ||
|
||
public static IEnumerable<ReferenceInfo> CreateDependencyReferenceInfos( | ||
IEnumerable<ITaskItem> referenceDependencyPaths, | ||
IEnumerable<ITaskItem> referenceSatellitePaths) | ||
{ | ||
IEnumerable<ITaskItem> indirectReferencePaths = referenceDependencyPaths | ||
.Where(r => r.HasMetadataValue("CopyLocal", "true") && | ||
string.IsNullOrEmpty(r.GetMetadata("NuGetSourceType"))); | ||
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 see NuGetSourceType around elsewhere, but I don't know what it's testing for. I think we may no longer be setting this anywhere. 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. It can probably be removed in a later PR, along with all the other uses, if it isn't actually needed anymore. 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.
If we removed this metadata, I'm not sure how things are working.... 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 did remove it along with a bunch of redundant goop that was filling the log file. Now I don't know how tests are passing, but something has probably regressed. :( 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. There is a regression: #2121 Unfortunate that we had no test coverage. I will add NuGetSourceType back |
||
|
||
return CreateFilteredReferenceInfos(indirectReferencePaths, referenceSatellitePaths); | ||
} | ||
|
||
private static IEnumerable<ReferenceInfo> CreateFilteredReferenceInfos( | ||
IEnumerable<ITaskItem> referencePaths, | ||
IEnumerable<ITaskItem> referenceSatellitePaths) | ||
{ | ||
Dictionary<string, ReferenceInfo> directReferences = new Dictionary<string, ReferenceInfo>(); | ||
foreach (ITaskItem directReferencePath in directReferencePaths) | ||
|
||
foreach (ITaskItem referencePath in referencePaths) | ||
{ | ||
ReferenceInfo referenceInfo = CreateReferenceInfo(directReferencePath); | ||
ReferenceInfo referenceInfo = CreateReferenceInfo(referencePath); | ||
directReferences.Add(referenceInfo.FullPath, referenceInfo); | ||
} | ||
|
||
|
@@ -76,7 +95,7 @@ public static IEnumerable<ReferenceInfo> CreateDirectReferenceInfos( | |
return directReferences.Values; | ||
} | ||
|
||
private static ReferenceInfo CreateReferenceInfo(ITaskItem referencePath) | ||
internal static ReferenceInfo CreateReferenceInfo(ITaskItem referencePath) | ||
{ | ||
string fullPath = referencePath.ItemSpec; | ||
string name = Path.GetFileNameWithoutExtension(fullPath); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,26 @@ internal class SingleProjectInfo | |
public string Version { get; } | ||
public string OutputName { get; } | ||
|
||
private List<ReferenceInfo> _dependencyReferences; | ||
public IEnumerable<ReferenceInfo> DependencyReferences | ||
{ | ||
get { return _dependencyReferences; } | ||
} | ||
|
||
private List<ResourceAssemblyInfo> _resourceAssemblies; | ||
public IEnumerable<ResourceAssemblyInfo> ResourceAssemblies | ||
{ | ||
get { return _resourceAssemblies; } | ||
} | ||
|
||
private SingleProjectInfo(string projectPath, string name, string version, string outputName, List<ResourceAssemblyInfo> resourceAssemblies) | ||
private SingleProjectInfo(string projectPath, string name, string version, string outputName, List<ReferenceInfo> dependencyReferences, List<ResourceAssemblyInfo> resourceAssemblies) | ||
{ | ||
ProjectPath = projectPath; | ||
Name = name; | ||
Version = version; | ||
OutputName = outputName; | ||
_resourceAssemblies = resourceAssemblies; | ||
_dependencyReferences = dependencyReferences ?? new List<ReferenceInfo>(); | ||
_resourceAssemblies = resourceAssemblies ?? new List<ResourceAssemblyInfo>(); | ||
} | ||
|
||
public static SingleProjectInfo Create(string projectPath, string name, string fileExtension, string version, ITaskItem[] satelliteAssemblies) | ||
|
@@ -37,64 +44,95 @@ public static SingleProjectInfo Create(string projectPath, string name, string f | |
|
||
foreach (ITaskItem satelliteAssembly in satelliteAssemblies) | ||
{ | ||
string culture = satelliteAssembly.GetMetadata("Culture"); | ||
string relativePath = satelliteAssembly.GetMetadata("TargetPath"); | ||
string culture = satelliteAssembly.GetMetadata(MetadataKeys.Culture); | ||
string relativePath = satelliteAssembly.GetMetadata(MetadataKeys.TargetPath); | ||
|
||
resourceAssemblies.Add(new ResourceAssemblyInfo(culture, relativePath)); | ||
} | ||
|
||
string outputName = name + fileExtension; | ||
return new SingleProjectInfo(projectPath, name, version, outputName, resourceAssemblies); | ||
return new SingleProjectInfo(projectPath, name, version, outputName, dependencyReferences: null, resourceAssemblies: resourceAssemblies); | ||
} | ||
|
||
public static Dictionary<string, SingleProjectInfo> CreateProjectReferenceInfos( | ||
IEnumerable<ITaskItem> referencePaths, | ||
IEnumerable<ITaskItem> referenceDependencyPaths, | ||
IEnumerable<ITaskItem> referenceSatellitePaths) | ||
{ | ||
Dictionary<string, SingleProjectInfo> projectReferences = new Dictionary<string, SingleProjectInfo>(); | ||
|
||
IEnumerable<ITaskItem> projectReferencePaths = referencePaths | ||
.Where(r => string.Equals(r.GetMetadata("ReferenceSourceTarget"), "ProjectReference", StringComparison.OrdinalIgnoreCase)); | ||
.Where(r => string.Equals(r.GetMetadata(MetadataKeys.ReferenceSourceTarget), "ProjectReference", StringComparison.OrdinalIgnoreCase)); | ||
|
||
foreach (ITaskItem projectReferencePath in projectReferencePaths) | ||
{ | ||
string sourceProjectFile = projectReferencePath.GetMetadata("MSBuildSourceProjectFile"); | ||
string sourceProjectFile = projectReferencePath.GetMetadata(MetadataKeys.MSBuildSourceProjectFile); | ||
|
||
if (string.IsNullOrEmpty(sourceProjectFile)) | ||
{ | ||
throw new BuildErrorException(Strings.MissingItemMetadata, "MSBuildSourceProjectFile", "ReferencePath", projectReferencePath.ItemSpec); | ||
throw new BuildErrorException(Strings.MissingItemMetadata, MetadataKeys.MSBuildSourceProjectFile, "ReferencePath", projectReferencePath.ItemSpec); | ||
} | ||
|
||
string outputName = Path.GetFileName(projectReferencePath.ItemSpec); | ||
string name = Path.GetFileNameWithoutExtension(outputName); | ||
string version = null; // it isn't possible to know the version from the MSBuild info. | ||
// The version will be retrieved from the project assets file. | ||
|
||
List<ResourceAssemblyInfo> resourceAssemblies = new List<ResourceAssemblyInfo>(); | ||
|
||
projectReferences.Add( | ||
sourceProjectFile, | ||
new SingleProjectInfo(sourceProjectFile, name, version, outputName, resourceAssemblies)); | ||
new SingleProjectInfo(sourceProjectFile, name, version, outputName, dependencyReferences: null, resourceAssemblies: null)); | ||
} | ||
|
||
IEnumerable<ITaskItem> projectReferenceDependencyPaths = referenceDependencyPaths | ||
.Where(r => string.Equals(r.GetMetadata(MetadataKeys.ReferenceSourceTarget), "ProjectReference", StringComparison.OrdinalIgnoreCase)); | ||
|
||
foreach (ITaskItem projectReferenceDependencyPath in projectReferenceDependencyPaths) | ||
{ | ||
string sourceProjectFile = projectReferenceDependencyPath.GetMetadata(MetadataKeys.MSBuildSourceProjectFile); | ||
|
||
if (string.IsNullOrEmpty(sourceProjectFile)) | ||
{ | ||
throw new BuildErrorException(Strings.MissingItemMetadata, MetadataKeys.MSBuildSourceProjectFile, "ReferenceDependencyPath", projectReferenceDependencyPath.ItemSpec); | ||
} | ||
|
||
SingleProjectInfo referenceProjectInfo; | ||
if (projectReferences.TryGetValue(sourceProjectFile, out referenceProjectInfo)) | ||
{ | ||
ReferenceInfo dependencyReferenceInfo = ReferenceInfo.CreateReferenceInfo(projectReferenceDependencyPath); | ||
referenceProjectInfo._dependencyReferences.Add(dependencyReferenceInfo); | ||
} | ||
} | ||
|
||
IEnumerable<ITaskItem> projectReferenceSatellitePaths = referenceSatellitePaths | ||
.Where(r => string.Equals(r.GetMetadata("ReferenceSourceTarget"), "ProjectReference", StringComparison.OrdinalIgnoreCase)); | ||
.Where(r => string.Equals(r.GetMetadata(MetadataKeys.ReferenceSourceTarget), "ProjectReference", StringComparison.OrdinalIgnoreCase)); | ||
|
||
foreach (ITaskItem projectReferenceSatellitePath in projectReferenceSatellitePaths) | ||
{ | ||
string sourceProjectFile = projectReferenceSatellitePath.GetMetadata("MSBuildSourceProjectFile"); | ||
string sourceProjectFile = projectReferenceSatellitePath.GetMetadata(MetadataKeys.MSBuildSourceProjectFile); | ||
|
||
if (string.IsNullOrEmpty(sourceProjectFile)) | ||
{ | ||
throw new BuildErrorException(Strings.MissingItemMetadata, "MSBuildSourceProjectFile", "ReferenceSatellitePath", projectReferenceSatellitePath.ItemSpec); | ||
throw new BuildErrorException(Strings.MissingItemMetadata, MetadataKeys.MSBuildSourceProjectFile, "ReferenceSatellitePath", projectReferenceSatellitePath.ItemSpec); | ||
} | ||
|
||
SingleProjectInfo referenceProjectInfo; | ||
if (projectReferences.TryGetValue(sourceProjectFile, out referenceProjectInfo)) | ||
{ | ||
ResourceAssemblyInfo resourceAssemblyInfo = | ||
ResourceAssemblyInfo.CreateFromReferenceSatellitePath(projectReferenceSatellitePath); | ||
referenceProjectInfo._resourceAssemblies.Add(resourceAssemblyInfo); | ||
string originalItemSpec = projectReferenceSatellitePath.GetMetadata(MetadataKeys.OriginalItemSpec); | ||
|
||
if (!string.IsNullOrEmpty(originalItemSpec)) | ||
{ | ||
ReferenceInfo referenceInfo = referenceProjectInfo._dependencyReferences.SingleOrDefault(r => r.FullPath.Equals(originalItemSpec)); | ||
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 concerned about the perf of doing N linear searches through M items here. |
||
|
||
if (referenceInfo is null) | ||
{ | ||
// We only want to add the reference satellite path if it isn't already covered by a dependency | ||
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. Do we have test coverage for this satellite path change? 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. No, looks like I forgot to push those, let me see if I still have them locally. 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. Fixed. 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. If it's already covered by dependency, will we have set locale? 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 what you are asking here. |
||
|
||
ResourceAssemblyInfo resourceAssemblyInfo = | ||
ResourceAssemblyInfo.CreateFromReferenceSatellitePath(projectReferenceSatellitePath); | ||
referenceProjectInfo._resourceAssemblies.Add(resourceAssemblyInfo); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
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 causes the "library" section to be populated properly.