Beispiel #1
0
        private static IEnumerable <ReferenceInfo> CreateFilteredReferenceInfos(
            IEnumerable <ITaskItem> referencePaths,
            IEnumerable <ITaskItem> referenceSatellitePaths)
        {
            Dictionary <string, ReferenceInfo> directReferences = new Dictionary <string, ReferenceInfo>();

            foreach (ITaskItem referencePath in referencePaths)
            {
                ReferenceInfo referenceInfo = CreateReferenceInfo(referencePath);
                directReferences.Add(referenceInfo.FullPath, referenceInfo);
            }

            foreach (ITaskItem referenceSatellitePath in referenceSatellitePaths)
            {
                string originalItemSpec = referenceSatellitePath.GetMetadata("OriginalItemSpec");
                if (!string.IsNullOrEmpty(originalItemSpec))
                {
                    ReferenceInfo referenceInfo;
                    if (directReferences.TryGetValue(originalItemSpec, out referenceInfo))
                    {
                        ResourceAssemblyInfo resourceAssemblyInfo =
                            ResourceAssemblyInfo.CreateFromReferenceSatellitePath(referenceSatellitePath);
                        referenceInfo._resourceAssemblies.Add(resourceAssemblyInfo);
                    }
                }
            }

            return(directReferences.Values);
        }
Beispiel #2
0
        public static IEnumerable <ReferenceInfo> CreateDirectReferenceInfos(
            IEnumerable <ITaskItem> referencePaths,
            IEnumerable <ITaskItem> referenceSatellitePaths)
        {
            IEnumerable <ITaskItem> directReferencePaths = referencePaths
                                                           .Where(r => r.HasMetadataValue("CopyLocal", "true") &&
                                                                  r.HasMetadataValue("ReferenceSourceTarget", "ResolveAssemblyReference") &&
                                                                  string.IsNullOrEmpty(r.GetMetadata("NuGetSourceType")));

            Dictionary <string, ReferenceInfo> directReferences = new Dictionary <string, ReferenceInfo>();

            foreach (ITaskItem directReferencePath in directReferencePaths)
            {
                ReferenceInfo referenceInfo = CreateReferenceInfo(directReferencePath);
                directReferences.Add(referenceInfo.FullPath, referenceInfo);
            }

            foreach (ITaskItem referenceSatellitePath in referenceSatellitePaths)
            {
                string originalItemSpec = referenceSatellitePath.GetMetadata("OriginalItemSpec");
                if (!string.IsNullOrEmpty(originalItemSpec))
                {
                    ReferenceInfo referenceInfo;
                    if (directReferences.TryGetValue(originalItemSpec, out referenceInfo))
                    {
                        ResourceAssemblyInfo resourceAssemblyInfo =
                            ResourceAssemblyInfo.CreateFromReferenceSatellitePath(referenceSatellitePath);
                        referenceInfo._resourceAssemblies.Add(resourceAssemblyInfo);
                    }
                }
            }

            return(directReferences.Values);
        }
Beispiel #3
0
        public static Dictionary <string, SingleProjectInfo> CreateProjectReferenceInfos(
            IEnumerable <ITaskItem> referencePaths,
            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));

            foreach (ITaskItem projectReferencePath in projectReferencePaths)
            {
                string sourceProjectFile = projectReferencePath.GetMetadata("MSBuildSourceProjectFile");

                if (string.IsNullOrEmpty(sourceProjectFile))
                {
                    throw new BuildErrorException(Strings.MissingItemMetadata, "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));
            }

            IEnumerable <ITaskItem> projectReferenceSatellitePaths = referenceSatellitePaths
                                                                     .Where(r => string.Equals(r.GetMetadata("ReferenceSourceTarget"), "ProjectReference", StringComparison.OrdinalIgnoreCase));

            foreach (ITaskItem projectReferenceSatellitePath in projectReferenceSatellitePaths)
            {
                string sourceProjectFile = projectReferenceSatellitePath.GetMetadata("MSBuildSourceProjectFile");

                if (string.IsNullOrEmpty(sourceProjectFile))
                {
                    throw new BuildErrorException(Strings.MissingItemMetadata, "MSBuildSourceProjectFile", "ReferenceSatellitePath", projectReferenceSatellitePath.ItemSpec);
                }

                SingleProjectInfo referenceProjectInfo;
                if (projectReferences.TryGetValue(sourceProjectFile, out referenceProjectInfo))
                {
                    ResourceAssemblyInfo resourceAssemblyInfo =
                        ResourceAssemblyInfo.CreateFromReferenceSatellitePath(projectReferenceSatellitePath);
                    referenceProjectInfo._resourceAssemblies.Add(resourceAssemblyInfo);
                }
            }

            return(projectReferences);
        }
Beispiel #4
0
        public static Dictionary <string, SingleProjectInfo> CreateProjectReferenceInfos(
            IEnumerable <ITaskItem> referencePaths,
            IEnumerable <ITaskItem> referenceDependencyPaths,
            IEnumerable <ITaskItem> referenceSatellitePaths)
        {
            Dictionary <string, SingleProjectInfo> projectReferences = new Dictionary <string, SingleProjectInfo>(StringComparer.OrdinalIgnoreCase);

            IEnumerable <ITaskItem> projectReferencePaths = referencePaths
                                                            .Where(r => string.Equals(r.GetMetadata(MetadataKeys.ReferenceSourceTarget), "ProjectReference", StringComparison.OrdinalIgnoreCase));

            foreach (ITaskItem projectReferencePath in projectReferencePaths)
            {
                string sourceProjectFile = projectReferencePath.GetMetadata(MetadataKeys.MSBuildSourceProjectFile);

                if (string.IsNullOrEmpty(sourceProjectFile))
                {
                    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.

                projectReferences.Add(
                    sourceProjectFile,
                    new SingleProjectInfo(sourceProjectFile, name, version, outputName, dependencyReferences: null, resourceAssemblies: null));
            }

            //  Include direct references of referenced projects, but only if they are CopyLocal
            IEnumerable <ITaskItem> projectReferenceDependencyPaths = referenceDependencyPaths
                                                                      .Where(r => string.Equals(r.GetMetadata(MetadataKeys.ReferenceSourceTarget), "ProjectReference", StringComparison.OrdinalIgnoreCase) &&
                                                                             MSBuildUtilities.ConvertStringToBool(r.GetMetadata(MetadataKeys.CopyLocal)));

            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(MetadataKeys.ReferenceSourceTarget), "ProjectReference", StringComparison.OrdinalIgnoreCase));

            foreach (ITaskItem projectReferenceSatellitePath in projectReferenceSatellitePaths)
            {
                string sourceProjectFile = projectReferenceSatellitePath.GetMetadata(MetadataKeys.MSBuildSourceProjectFile);

                if (string.IsNullOrEmpty(sourceProjectFile))
                {
                    throw new BuildErrorException(Strings.MissingItemMetadata, MetadataKeys.MSBuildSourceProjectFile, "ReferenceSatellitePath", projectReferenceSatellitePath.ItemSpec);
                }

                SingleProjectInfo referenceProjectInfo;
                if (projectReferences.TryGetValue(sourceProjectFile, out referenceProjectInfo))
                {
                    string originalItemSpec = projectReferenceSatellitePath.GetMetadata(MetadataKeys.OriginalItemSpec);

                    if (!string.IsNullOrEmpty(originalItemSpec))
                    {
                        ReferenceInfo referenceInfo = referenceProjectInfo._dependencyReferences.SingleOrDefault(r => r.FullPath.Equals(originalItemSpec));

                        if (referenceInfo is null)
                        {
                            // We only want to add the reference satellite path if it isn't already covered by a dependency

                            ResourceAssemblyInfo resourceAssemblyInfo =
                                ResourceAssemblyInfo.CreateFromReferenceSatellitePath(projectReferenceSatellitePath);
                            referenceProjectInfo._resourceAssemblies.Add(resourceAssemblyInfo);
                        }
                    }
                }
            }

            return(projectReferences);
        }