public ValidationPattern(ITaskItem item, TaskLoggingHelper log)
            {
                string idRegex = item.GetMetadata("IdentityRegex");
                if (string.IsNullOrEmpty(idRegex))
                {
                    // Temporarily support reading the regex from the Include/ItemSpec for backwards compatibility
                    // when the IdentityRegex isn't specified. This can be removed once all consumers are using IdentityRegex.
                    idRegex = item.ItemSpec;
                }

                _idPattern = new Regex(idRegex);
                _expectedVersion = item.GetMetadata("ExpectedVersion");
                _expectedPrerelease = item.GetMetadata("ExpectedPrerelease");
                _log = log;

                if (string.IsNullOrWhiteSpace(_expectedVersion))
                {
                    if (string.IsNullOrWhiteSpace(_expectedPrerelease))
                    {
                        _log.LogError(
                            "Can't find ExpectedVersion or ExpectedPrerelease metadata on item {0}",
                            item.ItemSpec);
                    }
                }
                else if (!string.IsNullOrWhiteSpace(_expectedPrerelease))
                {
                    _log.LogError(
                        "Both ExpectedVersion and ExpectedPrerelease metadata found on item {0}, but only one permitted",
                        item.ItemSpec);
                }
            }
예제 #2
0
        protected ITaskItem ConvertPackageElement(ITaskItem project, PackageReference packageReference)
        {
            var id = packageReference.Id;
            var version = packageReference.Version;
            var targetFramework = packageReference.TargetFramework;
            var isDevelopmentDependency = packageReference.IsDevelopmentDependency;
            var requireReinstallation = packageReference.RequireReinstallation;
            var versionConstraint = packageReference.VersionConstraint;

            var item = new TaskItem(id);
            project.CopyMetadataTo(item);

            var packageDirectoryPath = GetPackageDirectoryPath(project.GetMetadata("FullPath"), id, version);
            item.SetMetadata("PackageDirectoryPath", packageDirectoryPath);
            item.SetMetadata("ProjectPath", project.GetMetadata("FullPath"));

            item.SetMetadata("IsDevelopmentDependency", isDevelopmentDependency.ToString());
            item.SetMetadata("RequireReinstallation", requireReinstallation.ToString());

            if (version != null)
                item.SetMetadata(Metadata.Version, version.ToString());

            if (targetFramework != null)
                item.SetMetadata(Metadata.TargetFramework, targetFramework.GetShortFrameworkName());

            if (versionConstraint != null)
                item.SetMetadata("VersionConstraint", versionConstraint.ToString());

            return item;
        }
예제 #3
0
        public static string GetVirtualProjectPath(string projectDir, ITaskItem item)
        {
            var link = item.GetMetadata ("Link");

            // Note: if the Link metadata exists, then it will be the equivalent of the ProjectVirtualPath
            if (!string.IsNullOrEmpty (link)) {
                if (Path.DirectorySeparatorChar != '\\')
                    return link.Replace ('\\', '/');

                return link;
            }

            // HACK: This is for Visual Studio iOS projects
            if (!Directory.Exists (projectDir))
                return item.ItemSpec;

            var definingProjectFullPath = item.GetMetadata ("DefiningProjectFullPath");
            var path = item.GetMetadata ("FullPath");
            string baseDir;

            if (!string.IsNullOrEmpty (definingProjectFullPath)) {
                baseDir = Path.GetDirectoryName (definingProjectFullPath);
            } else {
                baseDir = projectDir;
            }

            baseDir = PathUtils.ResolveSymbolicLink (baseDir);
            path = PathUtils.ResolveSymbolicLink (path);

            return PathUtils.AbsoluteToRelative (baseDir, path);
        }
		static string GetLinkPath (ITaskItem file, string path)
		{
			string link = file.GetMetadata ("Link");
			if (!string.IsNullOrEmpty (link)) {
				return link;
			}

			string projectDir;
			var definingProject = file.GetMetadata ("DefiningProjectFullPath");
			if (!string.IsNullOrEmpty (definingProject)) {
				projectDir = Path.GetDirectoryName (definingProject);
			} else {
				projectDir = Environment.CurrentDirectory;
			}

			projectDir = Path.GetFullPath (projectDir);
			if (projectDir [projectDir.Length - 1] != Path.DirectorySeparatorChar) {
				projectDir += Path.DirectorySeparatorChar;
			}

			if (path.StartsWith (projectDir, StringComparison.Ordinal)) {
				link = path.Substring (projectDir.Length);
			} else {
				link = Path.GetFileName (path);
			}

			return link;
		}
        private static string GetMetadata(ITaskItem taskItem, TargetLanguage targetLanguage, string metadataName)
        {
            // Get metadata
            var metadata = taskItem?.GetMetadata($"{metadataName}");
            // Get prefixed metadata
            var prefixedMetadata = taskItem?.GetMetadata($"{targetLanguage}{metadataName}");

            return(string.IsNullOrWhiteSpace(prefixedMetadata)
                ? metadata
                : prefixedMetadata);
        }
        protected override void ExecuteCore()
        {
            // Get information on the runtime package used for the current target
            ITaskItem frameworkPack = RuntimePacks.Where(pack =>
                                                         pack.GetMetadata(MetadataKeys.FrameworkName).Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase))
                                      .SingleOrDefault();

            _runtimeIdentifier = frameworkPack?.GetMetadata(MetadataKeys.RuntimeIdentifier);
            _packagePath       = frameworkPack?.GetMetadata(MetadataKeys.PackageDirectory);

            // Get the list of runtime identifiers that we support and can target
            string supportedRuntimeIdentifiers = frameworkPack?.GetMetadata(MetadataKeys.AvailableRuntimeIdentifiers);

            var runtimeGraph      = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
            var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';');

            // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
            string hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
                runtimeGraph,
                NETCoreSdkRuntimeIdentifier,
                supportedRIDsList,
                out bool wasInGraph);

            if (hostRuntimeIdentifier == null || _runtimeIdentifier == null || _packagePath == null)
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return;
            }

            if (!ExtractTargetPlatformAndArchitecture(_runtimeIdentifier, out string targetPlatform, out _targetArchitecture) ||
                !ExtractTargetPlatformAndArchitecture(hostRuntimeIdentifier, out string hostPlatform, out Architecture hostArchitecture) ||
                targetPlatform != hostPlatform)
            {
                Log.LogError(Strings.ReadyToRunTargetNotSupportedError);
                return;
            }

            if (!GetCrossgenComponentsPaths() || !File.Exists(_crossgenPath) || !File.Exists(_clrjitPath))
            {
                Log.LogError(Strings.ReadyToRunTargetNotSupportedError);
                return;
            }

            // Create tool task item
            CrossgenTool = new TaskItem(_crossgenPath);
            CrossgenTool.SetMetadata("JitPath", _clrjitPath);
            if (!String.IsNullOrEmpty(_diasymreaderPath))
            {
                CrossgenTool.SetMetadata("DiaSymReader", _diasymreaderPath);
            }

            // Process input lists of files
            ProcessInputFileList(Assemblies, _compileList, _symbolsCompileList, _r2rFiles, _r2rReferences);
        }
예제 #7
0
        /// <summary>
        /// Creates a <see cref="VisualStudioComponent"/> using a workload definition.
        /// </summary>
        /// <param name="manifest"></param>
        /// <param name="workload"></param>
        /// <param name="componentVersions"></param>
        /// <param name="shortNames"></param>
        /// <param name="shortNameMetadata"></param>
        /// <param name="componentResources"></param>
        /// <returns></returns>
        public static VisualStudioComponent Create(TaskLoggingHelper log, WorkloadManifest manifest, WorkloadDefinition workload, ITaskItem[] componentVersions,
                                                   ITaskItem[] shortNames, ITaskItem[] componentResources, ITaskItem[] missingPacks)
        {
            log?.LogMessage("Creating Visual Studio component");
            string workloadId = $"{workload.Id}";

            // If there's an explicit version mapping we use that, otherwise we fall back to the manifest version
            // and normalize it since it can have semantic information and Visual Studio components do not support that.
            ITaskItem versionItem = componentVersions?.Where(v => string.Equals(v.ItemSpec, workloadId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            Version   version     = (versionItem != null) && !string.IsNullOrWhiteSpace(versionItem.GetMetadata(Metadata.Version))
                ? new Version(versionItem.GetMetadata(Metadata.Version))
                : (new NuGetVersion(manifest.Version)).Version;

            ITaskItem resourceItem = componentResources?.Where(
                r => string.Equals(r.ItemSpec, workloadId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            // Workload definitions do not have separate title/description fields so the only option
            // is to default to the workload description for both.
            string title       = resourceItem?.GetMetadata(Metadata.Title) ?? workload.Description;
            string description = resourceItem?.GetMetadata(Metadata.Description) ?? workload.Description;
            string category    = resourceItem?.GetMetadata(Metadata.Category) ?? ".NET";
            string isUiGroup   = workload.IsAbstract ? "yes" : "no";

            VisualStudioComponent component = new(Utils.ToSafeId(workloadId), description,
                                                  title, version, isUiGroup, shortNames, category);

            IEnumerable <string> missingPackIds = missingPacks.Select(p => p.ItemSpec);

            log?.LogMessage(MessageImportance.Low, $"Missing packs: {string.Join(", ", missingPackIds)}");

            // If the work extends other workloads, we add those as component dependencies before
            // processing direct pack dependencies
            if (workload.Extends?.Count() > 0)
            {
                foreach (WorkloadDefinitionId dependency in workload.Extends)
                {
                    // Component dependencies, aka. workload extensions only have minimum version dependencies.
                    component.AddDependency($"{Utils.ToSafeId(dependency.ToString())}", new Version("1.0.0.0"), maxVersion: null);
                }
            }

            // Visual Studio is case-insensitive.
            IEnumerable <WorkloadPackId> packIds = workload.Packs.Where(p => !missingPackIds.Contains($"{p}", StringComparer.OrdinalIgnoreCase));

            log?.LogMessage(MessageImportance.Low, $"Packs: {string.Join(", ", packIds.Select(p=>$"{p}"))}");

            foreach (WorkloadPackId packId in packIds)
            {
                log?.LogMessage(MessageImportance.Low, $"Adding component dependency for {packId} ");
                component.AddDependency(manifest.Packs[packId]);
            }

            return(component);
        }
예제 #8
0
		private string FindNamespace(ITaskItem item) {
			string s = item.GetMetadata("CustomToolNamespace");
			if (!string.IsNullOrEmpty(s))
				return s;	// Easy - the namespace was set explicitly
			s = item.GetMetadata("Link");	// If the Link metadata is set, it defines the file as the project sees it.
			string dir = Path.GetDirectoryName(!string.IsNullOrEmpty(s) ? s : item.ItemSpec);

			string rootNamespaceWithDot = RootNamespace;
			if (!string.IsNullOrEmpty(rootNamespaceWithDot) && !rootNamespaceWithDot.EndsWith(".") && !string.IsNullOrEmpty(dir))
				rootNamespaceWithDot += ".";
			return rootNamespaceWithDot + dir;
		}
예제 #9
0
 protected override IEnumerable<Replacing> GetReplacings(ITaskItem item, string text)
 {
     foreach (var repl in base.GetReplacings(item, text)) yield return repl;
     int i = 0;
     string n = i > 0 ? i.ToString() : "";
     string regex;
     while (!string.IsNullOrEmpty(regex = item.GetMetadata("Replacing"+n))) {
         int count;
         if (!int.TryParse(item.GetMetadata("ReplaceCount"+n) ?? "", out count)) count = -1;
         var options = ParseOptions(item.GetMetadata("ReplaceOptions"));
         yield return new Replacing { Expression = regex, Options = options, Count = count, Replacement = item.GetMetadata("Replacement"+n) };
         i++;
         n = i > 0 ? i.ToString() : "";
     }
 }
 protected XmlElement GetProjectElement(ITaskItem projectRef)
 {
     string metadata = projectRef.GetMetadata("Project");
     XmlElement element = null;
     if (this.cachedProjectElements.TryGetValue(metadata, out element) && (element != null))
     {
         return element;
     }
     string key = projectRef.GetMetadata("FullPath");
     if (this.cachedProjectElementsByAbsolutePath.TryGetValue(key, out element) && (element != null))
     {
         return element;
     }
     return null;
 }
예제 #11
0
        private ITaskItem ComputeLocalizedResource(ITaskItem xlf)
        {
            var resxName = xlf.GetMetadata("FileName");
            var resxFileName = resxName + ".resx";
            var resxPath = Path.Combine(LocalizedResxRoot, resxFileName);

            var resxItem = new TaskItem(resxPath);
            resxItem.SetMetadata(NeutralResxMetadata, xlf.GetMetadata(NeutralResxMetadata));
            resxItem.SetMetadata(ParentXlfMetadata, xlf.ItemSpec);
            resxItem.SetMetadata(ComputedCultureCodeMetadata, xlf.GetMetadata(ComputedCultureCodeMetadata));
            resxItem.SetMetadata(LogicalNameMetadata, $"{AssemblyName}.{resxName}.resources");

            xlf.SetMetadata(ChildResxMetadata, resxPath);

            return resxItem;
        }
예제 #12
0
 protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem hostItem)
 {
     return
         (bool.TryParse(hostItem?.GetMetadata(IsEnterpriseEditionMetadataName), out var isEnterpriseEdition) && !isEnterpriseEdition
             ? BuildSourceLinkUrlForCloudEdition(contentUri, relativeUrl, revisionId)
             : BuildSourceLinkUrlForEnterpriseEdition(contentUri, relativeUrl, revisionId, hostItem));
 }
예제 #13
0
        private bool ValidateCrossgenSupport()
        {
            _crossgenTool.PackagePath = _runtimePack?.GetMetadata(MetadataKeys.PackageDirectory);
            if (_crossgenTool.PackagePath == null)
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return(false);
            }

            if (!ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) ||
                !ExtractTargetPlatformAndArchitecture(_hostRuntimeIdentifier, out string hostPlatform, out Architecture hostArchitecture) ||
                _targetPlatform != hostPlatform ||
                !GetCrossgenComponentsPaths())
            {
                Log.LogError(Strings.ReadyToRunTargetNotSupportedError);
                return(false);
            }

            // Create tool task item
            CrossgenTool = new TaskItem(_crossgenTool.ToolPath);
            CrossgenTool.SetMetadata(MetadataKeys.JitPath, _crossgenTool.ClrJitPath);
            if (!String.IsNullOrEmpty(_crossgenTool.DiaSymReaderPath))
            {
                CrossgenTool.SetMetadata(MetadataKeys.DiaSymReader, _crossgenTool.DiaSymReaderPath);
            }

            return(true);
        }
예제 #14
0
        public PackageFile( ITaskItem item )
        {
            FullPath = item.GetMetadata( "FullPath" );
            PathInProject = item.ItemSpec;

            var environmentData = item.GetMetadata( "Environment" );
            if( string.IsNullOrEmpty( environmentData ) )
                environmentData = "None";

            var isDashboardData = item.GetMetadata( "IsDashboard" );
            if( string.IsNullOrEmpty( isDashboardData ) )
                isDashboardData = "false";

            Environment = ( TargetEnvironment )Enum.Parse( typeof( TargetEnvironment ), environmentData, true );
            IsDashboard = bool.Parse( isDashboardData );
        }
예제 #15
0
 static string GetTarget(ITaskItem x)
 {
     var target = x.GetMetadata("TargetPath");
     if (Path.GetFileName(x.ItemSpec) == Path.GetFileName(target))
         target = Path.GetDirectoryName(target);
     return target;
 }
예제 #16
0
        public string Parse(ITaskItem taskItem, bool fullOutputName, string outputExtension)
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            foreach (string name in taskItem.MetadataNames)
            {
                string value = taskItem.GetMetadata(name);
                if (outputExtension != null && name == "OutputFile")
                {
                    value = Path.ChangeExtension(value, outputExtension);
                }
                if (fullOutputName && name == "ObjectFileName")
                {
                    if ((File.GetAttributes(value) & FileAttributes.Directory) != 0)
                    {
                        value = Path.Combine(value, Path.GetFileName(taskItem.ItemSpec));
                        value = Path.ChangeExtension(value, ".obj");
                    }
                }
                AppendArgumentForProperty(builder, name, value);
            }

            string result = builder.ToString();
            result = result.Replace('\\', '/'); // posix paths
            return result;
        }
예제 #17
0
        private IEnumerable<ITaskItem> ResolvePackage(ITaskItem package)
        {
            string id = package.ItemSpec;
            string version = package.GetMetadata("Version");

            Log.LogMessage(MessageImportance.Normal, "Resolving Package Reference {0} {1}...", id, version);

            // Initial version just searches a machine-level repository

            var localFs = new PhysicalFileSystem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Lib"));
            var defaultResolver = new DefaultPackagePathResolver(localFs);
            var machineRepo = new LocalPackageRepository(defaultResolver, localFs);
            var buildRepo = new BuildPackageRepository();
            var remoteRepo = new DataServicePackageRepository(new Uri("https://nuget.org/api/v2"));
            var project = new BuildProjectSystem(ProjectDirectory, new FrameworkName(TargetFramework), CurrentReferences);
            var manager = new PackageManager(remoteRepo, defaultResolver, localFs, machineRepo);
            var projectManager = new ProjectManager(remoteRepo, defaultResolver, project, buildRepo);

            // Install the package
            var ver = new SemanticVersion(version);
            manager.PackageInstalling += manager_PackageInstalling;
            manager.InstallPackage(id, ver);
            projectManager.AddPackageReference(id, ver);

            return project.OutputReferences.Select(item =>
            {
                var name = AssemblyName.GetAssemblyName(item);
                return new TaskItem(name.FullName, new Dictionary<string, string>() {
                    {"HintPath", item },
                    {"Private", "true"}
                });
            });
        }
예제 #18
0
        private bool ValidateCrossgen2Support()
        {
            _crossgen2Tool.PackagePath = _crossgen2Pack?.GetMetadata(MetadataKeys.PackageDirectory);
            if (_crossgen2Tool.PackagePath == null)
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return(false);
            }

            // Crossgen2 only supports the following host->target compilation scenarios in net5.0:
            //      win-x64 -> win-x64
            //      linux-x64 -> linux-x64
            //      linux-musl-x64 -> linux-musl-x64
            if (_targetRuntimeIdentifier != _hostRuntimeIdentifier)
            {
                Log.LogError(Strings.ReadyToRunTargetNotSupportedError);
                return(false);
            }

            if (!GetCrossgen2ComponentsPaths())
            {
                Log.LogError(Strings.ReadyToRunTargetNotSupportedError);
                return(false);
            }

            // Create tool task item
            Crossgen2Tool = new TaskItem(_crossgen2Tool.ToolPath);
            Crossgen2Tool.SetMetadata("JitPath", _crossgen2Tool.ClrJitPath);
            if (!String.IsNullOrEmpty(_crossgen2Tool.DiaSymReaderPath))
            {
                Crossgen2Tool.SetMetadata("DiaSymReader", _crossgen2Tool.DiaSymReaderPath);
            }

            return(true);
        }
예제 #19
0
        private string ComputeNeutralXlfName(ITaskItem neutralResouce)
        {
            var filename = neutralResouce.GetMetadata("Filename");
            var xlfRootPath = LocalizationUtils.ComputeXlfRootPath(neutralResouce);

            return Path.Combine(xlfRootPath, filename + ".xlf");
        }
예제 #20
0
        private bool ValidateCrossgen2Support()
        {
            ITaskItem crossgen2Pack = Crossgen2Packs?.FirstOrDefault();

            _crossgen2Tool.PackagePath = crossgen2Pack?.GetMetadata(MetadataKeys.PackageDirectory);

            if (string.IsNullOrEmpty(_crossgen2Tool.PackagePath) ||
                !NuGetVersion.TryParse(crossgen2Pack.GetMetadata(MetadataKeys.NuGetPackageVersion), out NuGetVersion crossgen2PackVersion))
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return(false);
            }

            bool   version5          = crossgen2PackVersion.Major < 6;
            bool   isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture);
            string targetOS          = _targetPlatform switch
            {
                "linux" => "linux",
                "linux-musl" => "linux",
                "osx" => "osx",
                "win" => "windows",
                _ => null
            };

            // In .NET 5 Crossgen2 supported only the following host->target compilation scenarios:
            //      win-x64 -> win-x64
            //      linux-x64 -> linux-x64
            //      linux-musl-x64 -> linux-musl-x64
            isSupportedTarget = isSupportedTarget &&
                                targetOS != null &&
                                (!version5 || _targetRuntimeIdentifier == _hostRuntimeIdentifier) &&
                                GetCrossgen2ComponentsPaths(version5);

            if (!isSupportedTarget)
            {
                Log.LogError(Strings.ReadyToRunTargetNotSupportedError);
                return(false);
            }

            // Create tool task item
            Crossgen2Tool = new TaskItem(_crossgen2Tool.ToolPath);
            Crossgen2Tool.SetMetadata(MetadataKeys.IsVersion5, version5.ToString());
            if (version5)
            {
                Crossgen2Tool.SetMetadata(MetadataKeys.JitPath, _crossgen2Tool.ClrJitPath);
            }
            else
            {
                Crossgen2Tool.SetMetadata(MetadataKeys.TargetOS, targetOS);
                Crossgen2Tool.SetMetadata(MetadataKeys.TargetArch, ArchitectureToString(_targetArchitecture));
                if (!string.IsNullOrEmpty(PerfmapFormatVersion))
                {
                    Crossgen2Tool.SetMetadata(MetadataKeys.PerfmapFormatVersion, PerfmapFormatVersion);
                }
            }

            _crossgen2IsVersion5 = version5;
            return(true);
        }
예제 #21
0
        public PackageItem(ITaskItem item)
        {
            OriginalItem = item;
            SourcePath = item.GetMetadata("FullPath");
            SourceProject = GetMetadata("MSBuildSourceProjectFile");
            string value = GetMetadata("TargetFramework");
            if (!String.IsNullOrWhiteSpace(value))
            {
                TargetFramework = NuGetFramework.Parse(value);
            }
            TargetPath = item.GetMetadata(nameof(TargetPath));
            AdditionalProperties = GetMetadata(nameof(AdditionalProperties));
            UndefineProperties = GetMetadata(nameof(UndefineProperties));
            HarvestedFrom = GetMetadata(nameof(HarvestedFrom));
            Package = GetMetadata("PackageId");
            PackageVersion = GetMetadata("PackageVersion");
            IsDll = Path.GetExtension(SourcePath).Equals(".dll", StringComparison.OrdinalIgnoreCase);
            IsPlaceholder = NuGetAssetResolver.IsPlaceholder(SourcePath);
            IsRef = TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase);

            // determine if we need to append filename to TargetPath
            // see https://docs.nuget.org/create/nuspec-reference#specifying-files-to-include-in-the-package
            // SourcePath specifies file and target specifies file - do nothing
            // SourcePath specifies file and Target specifies directory - copy filename
            // SourcePath specifies wildcard files - copy wildcard
            // SourcePath specifies recursive wildcard - do not allow, recursive directory may impact asset selection
            //   we don't want to attempt to expand the wildcard since the build may not yet be complete.

            if (SourcePath.Contains("**"))
            {
                throw new ArgumentException($"Recursive wildcards \"**\" are not permitted in source paths for packages: {SourcePath}.  Recursive directory may impact asset selection and we don't want to attempt to expand the wildcard since the build may not yet be complete.");
            }

            string sourceFile = Path.GetFileName(SourcePath);
            if (!Path.GetExtension(TargetPath).Equals(Path.GetExtension(sourceFile), StringComparison.OrdinalIgnoreCase) ||
                sourceFile.Contains("*"))
            {
                TargetPath = Path.Combine(TargetPath, sourceFile);
            }

            // standardize to /
            TargetPath = TargetPath.Replace('\\', '/');

            int dirLength = TargetPath.LastIndexOf('/');
            TargetDirectory = (dirLength > 0) ? TargetPath.Substring(0, dirLength) : String.Empty;
        }
예제 #22
0
        internal BuiltItem(string targetName, ITaskItem item)
        {
            TargetName = targetName;
            OutputPath = item.ItemSpec;

            foreach (var name in item.MetadataNames)
                Metadata.Add((string)name, item.GetMetadata((string)name));
        }
예제 #23
0
        public void UpdateProperties(string propertyOverrides, ITaskItem project, TaskLoggingHelper log)
        {
            log.LogMessage(MessageImportance.Normal, "Updating properties in file {0}", resourceFile.FullName);

            if (string.IsNullOrWhiteSpace(propertyOverrides)) return;

            var properties = propertyOverrides.ToDictionary(';', '=');

            // Scan meta data for project-specific overrides
            var metaDataNames = project.MetadataNames;
            foreach (string metaDataName in metaDataNames)
            {
                properties[metaDataName] = project.GetMetadata(metaDataName);
            }

            var lines = File.ReadLines(resourceFile.FullName).ToList();
            var results = new List<string>(lines.Count);

            // Now process each line in the file)
            foreach (var line in lines)
            {
                var key = GetKey(line);

                if (key == null)
                {
                    results.Add(line);
                }
                else
                {
                    var isValueKey = false;

                    if (key.Equals("VALUE", StringComparison.OrdinalIgnoreCase))
                    {
                        key = GetValueKey(line);
                        if (string.IsNullOrEmpty(key))
                        {
                            results.Add(line);
                            continue;
                        }

                        isValueKey = true;
                    }

                    if (properties.ContainsKey(key))
                    {
                        log.LogMessage(MessageImportance.Low, "Setting \"{0}\" to \"{1}\"", key, properties[key]);
                        results.Add(string.Format(isValueKey ? "VALUE \"{0}\", \"{1}\\0\"" : "{0} {1}", key, properties[key]));
                    }
                    else
                    {
                        results.Add(line);
                    }
                }
            }

            File.WriteAllLines(resourceFile.FullName, results);
        }
예제 #24
0
        private static string GetVirtualPath(string sourceDirectory, ITaskItem taskItem)
        {
            var file = taskItem.GetMetadata("Link");
            if (string.IsNullOrEmpty(file))
            {
                file = taskItem.ItemSpec;
            }

            return GetVirtualPath(sourceDirectory, file);
        }
예제 #25
0
        protected override void ExecuteCore()
        {
            _runtimePack             = GetNETCoreAppRuntimePack();
            _crossgen2Pack           = Crossgen2Packs?.FirstOrDefault();
            _targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier);

            // Get the list of runtime identifiers that we support and can target
            ITaskItem targetingPack = GetNETCoreAppTargetingPack();
            string    supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers);

            var runtimeGraph      = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
            var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';');

            // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
            _hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
                runtimeGraph,
                NETCoreSdkRuntimeIdentifier,
                supportedRIDsList,
                out bool wasInGraph);

            if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null)
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return;
            }

            if (ReadyToRunUseCrossgen2)
            {
                if (!ValidateCrossgen2Support())
                {
                    return;
                }

                // NOTE: Crossgen2 does not yet currently support emitting native symbols, and until this feature
                // is implemented, we will use crossgen for it. This should go away in the future when crossgen2 supports the feature.
                if (EmitSymbols && !ValidateCrossgenSupport())
                {
                    return;
                }
            }
            else
            {
                if (!ValidateCrossgenSupport())
                {
                    return;
                }
            }

            // Future: check DiaSymReaderPath in the _crossgen2Tool info when crossgen2 starts supporting emitting native symbols
            bool hasValidDiaSymReaderLib = String.IsNullOrEmpty(_crossgenTool.DiaSymReaderPath) ? false : File.Exists(_crossgenTool.DiaSymReaderPath);

            // Process input lists of files
            ProcessInputFileList(Assemblies, _compileList, _symbolsCompileList, _r2rFiles, _r2rReferences, hasValidDiaSymReaderLib);
        }
예제 #26
0
        private string GetRequestedRuntimeFrameworkVersion(ITaskItem frameworkReference)
        {
            string requestedVersion = frameworkReference?.GetMetadata("RuntimeFrameworkVersion");

            if (string.IsNullOrEmpty(requestedVersion))
            {
                requestedVersion = RuntimeFrameworkVersion;
            }

            return(requestedVersion);
        }
예제 #27
0
 protected override IEnumerable<Replacing> GetReplacings(ITaskItem item, string text)
 {
     var ns = Namespaces + item.GetMetadata("AddUsings") ?? "";
     var nss = ns.Trim(' ', '\t', '\n', '\r', ';').Replace("using", "").Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", "").Split(';')
         .Distinct()
         .OrderBy(s => s)
         .ToArray();
     Replacement = "$0#pragma warning disable 105\r\nusing " + string.Join(";\r\nusing ", nss) + ";\r\n\r\n";
     Count = 1;
     return base.GetReplacings(item, text);
 }
예제 #28
0
 protected override IEnumerable<Replacing> GetReplacings(ITaskItem item, string text)
 {
     foreach (var repl in base.GetReplacings(item, text)) yield return Filter(repl);
     if (Custom || string.IsNullOrEmpty(Regex)) {
         int i = 0;
         string n = i > 0 ? i.ToString() : "";
         string regex;
         while (!string.IsNullOrEmpty(regex = item.GetMetadata("CommentOut"+n))) {
             int count;
             if (!int.TryParse(item.GetMetadata("CommentOutCount"+n) ?? "", out count)) count = -1;
             var optmeta = item.GetMetadata("CommentOutOptions");
             var options = string.IsNullOrEmpty(optmeta) ? RegexOptions : ParseOptions(optmeta);
             var repl = item.GetMetadata("CommentOutReplacement"+n);
             if (string.IsNullOrEmpty(repl)) repl = Replacement ?? "";
             yield return Filter(new Replacing { Expression = regex, Options = options, Count = count, Replacement = repl });
             i++;
             n = i > 0 ? i.ToString() : "";
         }
     }
 }
        public static string GetMetadata(this ITaskItem item, string metadataName, string defaultValue)
        {
            var value = item?.GetMetadata(metadataName);

            if (string.IsNullOrEmpty(value))
            {
                return(defaultValue);
            }

            return(value);
        }
        protected internal AssemblyReference AddAssemblyFromItem(ITaskItem item)
        {
            AssemblyReferenceType managedAssembly;
            AssemblyReference reference;
            if (this.IsEmbedInteropEnabledForAssembly(item))
            {
                return null;
            }
            switch (this.GetItemAssemblyType(item))
            {
                case AssemblyType.Managed:
                    managedAssembly = AssemblyReferenceType.ManagedAssembly;
                    break;

                case AssemblyType.Native:
                    managedAssembly = AssemblyReferenceType.NativeAssembly;
                    break;

                case AssemblyType.Satellite:
                    managedAssembly = AssemblyReferenceType.ManagedAssembly;
                    break;

                default:
                    managedAssembly = AssemblyReferenceType.Unspecified;
                    break;
            }
            if (this.GetItemDependencyType(item) == DependencyType.Install)
            {
                reference = this.manifest.AssemblyReferences.Add(item.ItemSpec);
                this.SetItemAttributes(item, reference);
            }
            else
            {
                AssemblyIdentity identity = AssemblyIdentity.FromAssemblyName(item.ItemSpec);
                if (identity.IsStrongName)
                {
                    reference = new AssemblyReference {
                        AssemblyIdentity = identity
                    };
                }
                else
                {
                    reference = new AssemblyReference(item.ItemSpec);
                }
                this.manifest.AssemblyReferences.Add(reference);
                reference.IsPrerequisite = true;
            }
            reference.ReferenceType = managedAssembly;
            if (string.Equals(item.GetMetadata("IsPrimary"), "true", StringComparison.Ordinal))
            {
                reference.IsPrimary = true;
            }
            return reference;
        }
예제 #31
0
        public static IList<string> GetResourceTags(ITaskItem item)
        {
            var tags = ParseTags (item.GetMetadata ("ResourceTags"));

            if (tags.Length == 0)
                return null;

            Array.Sort (tags, StringComparer.Ordinal);

            return tags;
        }
예제 #32
0
        public static NameValueCollection GetCustomItemMetadata(ITaskItem taskItem) 
        {                     
            var nameValueCollection = new NameValueCollection();

            foreach (string key in taskItem.CloneCustomMetadata().Keys)
            {
                nameValueCollection.Add(key, taskItem.GetMetadata(key));
            }

            return nameValueCollection;
        }
        public static TEnum GetEnumFromMetadata <TEnum>(this ITaskItem item, string metadataName, TEnum defaultValue)
            where TEnum : struct
        {
            var value = item?.GetMetadata(metadataName);

            if (!string.IsNullOrEmpty(value) && Enum.TryParse <TEnum>(value, out var output))
            {
                return(output);
            }

            return(defaultValue);
        }
예제 #34
0
 static string GetObjectFile(ITaskItem source)
 {
     string objectFilePath = Path.GetFullPath(source.GetMetadata("ObjectFileName"));
     // cl.exe will accept a folder name as the ObjectFileName in which case
     // the objectfile is created as <ObjectFileName>/<basename>.obj.  Here
     // we mimic this behaviour.
     if ((File.GetAttributes(objectFilePath) & FileAttributes.Directory) != 0)
     {
         objectFilePath = Path.Combine(objectFilePath, Path.GetFileName(source.ItemSpec));
         objectFilePath = Path.ChangeExtension(objectFilePath, ".obj");
     }
     return objectFilePath;
 }
            public ValidationPattern(ITaskItem item, TaskLoggingHelper log)
            {
                _idPattern = new Regex(item.ItemSpec);
                _expectedVersion = item.GetMetadata("ExpectedVersion");
                _expectedPrerelease = item.GetMetadata("ExpectedPrerelease");
                _log = log;

                if (string.IsNullOrWhiteSpace(_expectedVersion))
                {
                    if (string.IsNullOrWhiteSpace(_expectedPrerelease))
                    {
                        _log.LogError(
                            "Can't find ExpectedVersion or ExpectedPrerelease metadata on item {0}",
                            item.ItemSpec);
                    }
                }
                else if (!string.IsNullOrWhiteSpace(_expectedPrerelease))
                {
                    _log.LogError(
                        "Both ExpectedVersion and ExpectedPrerelease metadata found on item {0}, but only one permitted",
                        item.ItemSpec);
                }
            }
예제 #36
0
        public bool Execute()
        {
            const string fullPath = "FullPath";
            string       src      = SourceFile.GetMetadata(fullPath);
            string       dest     = (DestinationFile?.GetMetadata(fullPath) ?? Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), "appsettings.json"));

            foreach (string path in JPath.Split(new char[] { ';', ',' }, System.StringSplitOptions.RemoveEmptyEntries))
            {
                JsonEditor.CopyProperty(src, dest, path);
                BuildEngine.LogMessageEvent(new BuildMessageEventArgs(
                                                $"Copied  '{Path.GetFileName(src)}':'{path}' property to '{Path.GetFileName(dest)}'", null, nameof(CopyJsonProperties), MessageImportance.Normal));
            }

            return(true);
        }
            public Dependency(ITaskItem originalItem)
            {
                OriginalItem = originalItem;
                Name = originalItem.ItemSpec;
                string fx = originalItem.GetMetadata("TargetFramework");
                if (!String.IsNullOrEmpty(fx))
                {
                    TargetFramework = NuGetFramework.Parse(fx);
                }
                else
                {
                    TargetFramework = null;
                }

                string minNSFx = originalItem.GetMetadata("MinimumNETStandard");
                if (!String.IsNullOrEmpty(minNSFx))
                {
                    MinimumNETStandard = NuGetFramework.Parse(minNSFx);
                }
                else
                {
                    MinimumNETStandard = null;
                }
            }
예제 #38
0
        /// <summary>
        /// Creates a <see cref="VisualStudioComponent"/> using a workload definition.
        /// </summary>
        /// <param name="manifest"></param>
        /// <param name="workload"></param>
        /// <param name="componentVersion"></param>
        /// <param name="shortNames"></param>
        /// <param name="shortNameMetadata"></param>
        /// <param name="componentResources"></param>
        /// <returns></returns>
        public static VisualStudioComponent Create(TaskLoggingHelper log, WorkloadManifest manifest, WorkloadDefinition workload, string componentVersion,
                                                   ITaskItem[] shortNames, ITaskItem[] componentResources, ITaskItem[] missingPacks)
        {
            log?.LogMessage("Creating Visual Studio component");
            Version version = string.IsNullOrWhiteSpace(componentVersion) ? new Version($"{manifest.Version}.0") :
                              new Version(componentVersion);

            ITaskItem resourceItem = componentResources?.Where(
                r => string.Equals(r.ItemSpec, workload.Id.ToString(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            // Workload definitions do not have separate title/description fields so the only option
            // is to default to the workload description for both.
            string title       = resourceItem?.GetMetadata(Metadata.Title) ?? workload.Description;
            string description = resourceItem?.GetMetadata(Metadata.Description) ?? workload.Description;
            string category    = resourceItem?.GetMetadata(Metadata.Category) ?? ".NET";

            VisualStudioComponent component = new(Utils.ToSafeId(workload.Id.ToString()), description,
                                                  title, version, shortNames, category);

            IEnumerable <string> missingPackIds = missingPacks.Select(p => p.ItemSpec);

            log?.LogMessage(MessageImportance.Low, $"Missing packs: {string.Join(", ", missingPackIds)}");

            // Visual Studio is case-insensitive.
            IEnumerable <WorkloadPackId> packIds = workload.Packs.Where(p => !missingPackIds.Contains($"{p}", StringComparer.OrdinalIgnoreCase));

            log?.LogMessage(MessageImportance.Low, $"Packs: {string.Join(", ", packIds.Select(p=>$"{p}"))}");

            foreach (WorkloadPackId packId in packIds)
            {
                log?.LogMessage(MessageImportance.Low, $"Adding component dependency for {packId} ");
                component.AddDependency(manifest.Packs[packId]);
            }

            return(component);
        }
예제 #39
0
        protected override string?BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem?hostItem)
        {
            var virtualDirectory = hostItem?.GetMetadata(VirtualDirectoryMetadataName) ?? "";

            if (!AzureDevOpsUrlParser.TryParseOnPremHttp(relativeUrl, virtualDirectory, out var projectPath, out var repositoryName))
            {
                Log.LogError(CommonResources.ValueOfWithIdentityIsInvalid, Names.SourceRoot.RepositoryUrlFullName, SourceRoot.ItemSpec, gitUri);
                return(null);
            }

            return
                (UriUtilities.Combine(
                     UriUtilities.Combine(contentUri.ToString(), projectPath), $"_apis/git/repositories/{repositoryName}/items") +
                 $"?api-version=1.0&versionType=commit&version={revisionId}&path=/*");
        }
예제 #40
0
 public TestManifest(ITaskItem manifestTaskItem, DirectoryInfo outputDirectory, string defaultNamespace, bool nameForParentDirectory)
 {
     ManifestFilePath = manifestTaskItem.ItemSpec;
     ManifestDirectory = new Uri(Path.GetFullPath(Path.GetDirectoryName(ManifestFilePath)));
     var className = manifestTaskItem.GetMetadata("TestClass");
     if (String.IsNullOrEmpty(className))
     {
         if (nameForParentDirectory)
         {
             FileInfo f = new FileInfo(ManifestFilePath);
             className = f.Directory.Name;
         }
         else 
         {
             className = Path.GetFileNameWithoutExtension(ManifestFilePath);
         }
     }
     ClassName = CleanupClassName(className);
     OutputFilePath = outputDirectory.FullName + Path.DirectorySeparatorChar + ClassName + ".cs";
     Namespace = manifestTaskItem.GetMetadata("TestNamespace");
     if (String.IsNullOrEmpty(Namespace)) Namespace = defaultNamespace;
     _testCases = new List<SparqlTestCase>();
     ProcessManifest();
 }
예제 #41
0
        protected override void ExecuteCore()
        {
            _runtimePack             = GetNETCoreAppRuntimePack();
            _crossgen2Pack           = Crossgen2Packs?.FirstOrDefault();
            _targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier);

            // Get the list of runtime identifiers that we support and can target
            ITaskItem targetingPack = GetNETCoreAppTargetingPack();
            string    supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers);

            var runtimeGraph      = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
            var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';');

            // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
            _hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
                runtimeGraph,
                NETCoreSdkRuntimeIdentifier,
                supportedRIDsList,
                out _);

            if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null)
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return;
            }

            if (ReadyToRunUseCrossgen2)
            {
                if (!ValidateCrossgen2Support())
                {
                    return;
                }

                // NOTE: Crossgen2 does not yet currently support emitting native symbols, and until this feature
                // is implemented, we will use crossgen for it. This should go away in the future when crossgen2 supports the feature.
                if (EmitSymbols && !ValidateCrossgenSupport())
                {
                    return;
                }
            }
            else
            {
                if (!ValidateCrossgenSupport())
                {
                    return;
                }
            }
        }
예제 #42
0
        private Version GetVersion(ITaskItem?hostItem)
        {
            var versionAsString = hostItem?.GetMetadata(VersionMetadataName);

            if (!NullableString.IsNullOrEmpty(versionAsString))
            {
                if (Version.TryParse(versionAsString, out var version))
                {
                    return(version);
                }

                Log.LogError(CommonResources.ItemOfItemGroupMustSpecifyMetadata, hostItem !.ItemSpec, HostsItemGroupName, VersionMetadataName);
            }

            return(s_versionWithNewUrlFormat);
        }
예제 #43
0
        protected override void ExecuteCore()
        {
            _runtimePack             = GetNETCoreAppRuntimePack();
            _crossgen2Pack           = Crossgen2Packs?.FirstOrDefault();
            _targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier);

            // Get the list of runtime identifiers that we support and can target
            ITaskItem targetingPack = GetNETCoreAppTargetingPack();
            string    supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers);

            var runtimeGraph      = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
            var supportedRIDsList = supportedRuntimeIdentifiers == null?Array.Empty <string>() : supportedRuntimeIdentifiers.Split(';');

            // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
            _hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
                runtimeGraph,
                NETCoreSdkRuntimeIdentifier,
                supportedRIDsList,
                out _);

            if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null)
            {
                Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
                return;
            }

            if (ReadyToRunUseCrossgen2)
            {
                if (!ValidateCrossgen2Support())
                {
                    return;
                }

                // In .NET 5 Crossgen2 did not support emitting native symbols, so we use Crossgen to emit them
                if (_crossgen2IsVersion5 && EmitSymbols && !ValidateCrossgenSupport())
                {
                    return;
                }
            }
            else
            {
                if (!ValidateCrossgenSupport())
                {
                    return;
                }
            }
        }
예제 #44
0
        internal static bool TryConvertItemMetadataToBool(ITaskItem item, string itemMetadataName)
        {
            string metadataValue = item.GetMetadata(itemMetadataName);
            if (metadataValue == null || metadataValue.Length == 0)
            {
                return false;
            }

            try
            {
                return Utilities.ConvertStringToBool(metadataValue);
            }
            catch (System.ArgumentException)
            {
                throw new Exception("Invalid metadata attribute: " + itemMetadataName + " " + metadataValue);
            }
        }
예제 #45
0
        private KnownRuntimePack?SelectRuntimePack(ITaskItem frameworkReference, KnownFrameworkReference knownFrameworkReference, List <KnownRuntimePack> knownRuntimePacks)
        {
            var requiredLabelsMetadata = frameworkReference?.GetMetadata(MetadataKeys.RuntimePackLabels) ?? "";

            HashSet <string> requiredRuntimePackLabels = null;

            if (frameworkReference != null)
            {
                requiredRuntimePackLabels = new HashSet <string>(requiredLabelsMetadata.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries), StringComparer.OrdinalIgnoreCase);
            }

            //  The runtime pack name matches the RuntimeFrameworkName on the KnownFrameworkReference
            var matchingRuntimePacks = knownRuntimePacks.Where(krp => krp.Name.Equals(knownFrameworkReference.RuntimeFrameworkName, StringComparison.OrdinalIgnoreCase))
                                       .Where(krp =>
            {
                if (requiredRuntimePackLabels == null)
                {
                    return(krp.RuntimePackLabels.Length == 0);
                }
                else
                {
                    return(requiredRuntimePackLabels.SetEquals(krp.RuntimePackLabels));
                }
            })
                                       .ToList();

            if (matchingRuntimePacks.Count == 0)
            {
                return(null);
            }
            else if (matchingRuntimePacks.Count == 1)
            {
                return(matchingRuntimePacks[0]);
            }
            else
            {
                string runtimePackDescriptionForErrorMessage = knownFrameworkReference.RuntimeFrameworkName +
                                                               (requiredLabelsMetadata == string.Empty ? string.Empty : ":" + requiredLabelsMetadata);

                Log.LogError(Strings.ConflictingRuntimePackInformation, runtimePackDescriptionForErrorMessage,
                             string.Join(Environment.NewLine, matchingRuntimePacks.Select(rp => rp.RuntimePackNamePatterns)));

                return(knownFrameworkReference.ToKnownRuntimePack());
            }
        }
예제 #46
0
 private static ITaskItem ConvertToPackageFile(ITaskItem output)
 {
     var fileName = output.ItemSpec;
     var targetPath = output.GetMetadata("TargetPath");
     targetPath = string.IsNullOrEmpty(targetPath) ? Path.GetFileName(fileName) : targetPath;
     var frameworkNameMoniker = output.GetTargetFrameworkMoniker();
     var packageDirectory = output.GetPackageDirectory();
     var targetSubdirectory = output.GetTargetSubdirectory();
     var targetFramework = packageDirectory == PackageDirectory.Analyzers
         ? frameworkNameMoniker.GetAnalyzersFrameworkName()
         : frameworkNameMoniker.GetShortFrameworkName();
     var metadata = output.CloneCustomMetadata();
     metadata[Metadata.TargetFramework] = targetFramework;
     metadata[Metadata.PackageDirectory] = packageDirectory.ToString();
     metadata[Metadata.TargetSubdirectory] = targetSubdirectory;
     metadata[Metadata.FileTarget] = packageDirectory.Combine(targetFramework, targetSubdirectory, targetPath);
     return new TaskItem(fileName, metadata);
 }
예제 #47
0
        private IEnumerable<ITaskItem> ComputeXlfResourceItems(ITaskItem neutralResource)
        {
            var neutralResxRootDirectory = Path.GetDirectoryName(neutralResource.GetMetadata("FullPath"));
            var xlfRootPath = Path.Combine(neutralResxRootDirectory, RelativePathToXlfRoot);

            if (!Directory.Exists(xlfRootPath))
            {
                throw new InvalidOperationException(
                    $"Could not find expected xlf root {xlfRootPath} next to its neutral resource {neutralResource.ItemSpec}");
            }

            var resx = neutralResource.ItemSpec;

            return
                (Directory.EnumerateFiles(xlfRootPath)
                    .Where(f => IsValidXlf(f, resx))
                    .Select((f => CreateXLFTaskItemForNeutralResx(f, resx))));
        }
예제 #48
0
        public string ProcessProperties(ITaskItem taskItem)
        {
            StringBuilder returnStr = new StringBuilder(Utils.EST_MAX_CMDLINE_LEN);

            foreach ( string metaName in taskItem.MetadataNames )
            {
                string propValue = taskItem.GetMetadata(metaName);
                string processed = ProcessProperty(metaName, propValue).Trim();

                if (( processed != null ) && ( processed.Length > 0 ))
                {
                    returnStr.Append(processed);
                    returnStr.Append(" ");
                }
            }

            return returnStr.ToString().Trim();
        }
예제 #49
0
        private RuntimePatchRequest GetRuntimePatchRequest(ITaskItem frameworkReference)
        {
            string value = frameworkReference?.GetMetadata("TargetLatestRuntimePatch");

            if (!string.IsNullOrEmpty(value))
            {
                return(MSBuildUtilities.ConvertStringToBool(value, defaultValue: false)
                    ? RuntimePatchRequest.UseLatestVersion
                    : RuntimePatchRequest.UseDefaultVersion);
            }

            if (TargetLatestRuntimePatch)
            {
                return(RuntimePatchRequest.UseLatestVersion);
            }

            return(TargetLatestRuntimePatchIsDefault
                ? RuntimePatchRequest.UseDefaultVersionWithLatestRuntimePack
                : RuntimePatchRequest.UseDefaultVersion);
        }
        protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem hostItem)
        {
            // The SourceLinkBitbucketGitHost item for bitbucket.org specifies EnterpriseEdition="false".
            // Other items that may be specified by the project default to EnterpriseEdition="true" without specifying it.
            bool isCloud = bool.TryParse(hostItem?.GetMetadata(IsEnterpriseEditionMetadataName), out var isEnterpriseEdition) && !isEnterpriseEdition;

            if (isCloud)
            {
                return(BuildSourceLinkUrlForCloudEdition(contentUri, relativeUrl, revisionId));
            }

            if (TryParseEnterpriseUrl(relativeUrl, out var relativeBaseUrl, out var projectName, out var repositoryName))
            {
                var version = GetBitbucketEnterpriseVersion(hostItem);
                return(BuildSourceLinkUrlForEnterpriseEdition(contentUri, relativeBaseUrl, projectName, repositoryName, revisionId, version));
            }

            Log.LogError(CommonResources.ValueOfWithIdentityIsInvalid, Names.SourceRoot.RepositoryUrlFullName, SourceRoot.ItemSpec, gitUri);
            return(null);
        }
        private Version GetBitbucketEnterpriseVersion(ITaskItem hostItem)
        {
            var     bitbucketEnterpriseVersionAsString = hostItem?.GetMetadata(VersionMetadataName);
            Version bitbucketEnterpriseVersion;

            if (!string.IsNullOrEmpty(bitbucketEnterpriseVersionAsString))
            {
                if (!Version.TryParse(bitbucketEnterpriseVersionAsString, out bitbucketEnterpriseVersion))
                {
                    Log.LogError(CommonResources.ItemOfItemGroupMustSpecifyMetadata, hostItem.ItemSpec,
                                 HostsItemGroupName, VersionMetadataName);

                    return(null);
                }
            }
            else
            {
                bitbucketEnterpriseVersion = s_versionWithNewUrlFormat;
            }

            return(bitbucketEnterpriseVersion);
        }
예제 #52
0
        private bool BuildProject(ITaskItem project)
        {
            using (Process proc = new Process())
            {
                if (!string.IsNullOrEmpty(project.GetMetadata("ChgPropVBP")))
                {
                    this.LogTaskMessage("START - Changing Properties VBP");

                    VBPProject projectVBP = new VBPProject(project.ItemSpec);
                    if (projectVBP.Load())
                    {
                        string[] linesProperty = project.GetMetadata("ChgPropVBP").Split(Separator);
                        string[] keyProperty   = new string[linesProperty.Length];
                        string[] valueProperty = new string[linesProperty.Length];
                        int      index;

                        for (index = 0; index <= linesProperty.Length - 1; index++)
                        {
                            if (linesProperty[index].IndexOf("=", StringComparison.OrdinalIgnoreCase) != -1)
                            {
                                keyProperty[index]   = linesProperty[index].Substring(0, linesProperty[index].IndexOf("=", StringComparison.OrdinalIgnoreCase));
                                valueProperty[index] = linesProperty[index].Substring(linesProperty[index].IndexOf("=", StringComparison.OrdinalIgnoreCase) + 1);
                            }

                            if (!string.IsNullOrEmpty(keyProperty[index]) && !string.IsNullOrEmpty(valueProperty[index]))
                            {
                                this.LogTaskMessage(keyProperty[index] + " -> New value: " + valueProperty[index]);
                                projectVBP.SetProjectProperty(keyProperty[index], valueProperty[index], false);
                            }
                        }

                        projectVBP.Save();
                    }

                    this.LogTaskMessage("END - Changing Properties VBP");
                }

                FileInfo artifactFileInfo = null;
                if (this.IfModificationExists)
                {
                    this.LogTaskMessage("START - Checking for modified files");
                    bool       doBuild    = false;
                    VBPProject projectVBP = new VBPProject(project.ItemSpec);
                    if (projectVBP.Load())
                    {
                        FileInfo projectFileInfo = new FileInfo(projectVBP.ProjectFile);
                        artifactFileInfo = projectVBP.ArtifactFile;
                        this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "artifactFile '{0}', LastWrite: {1}'", artifactFileInfo.FullName, artifactFileInfo.LastWriteTime));

                        if (projectFileInfo.LastWriteTime > artifactFileInfo.LastWriteTime)
                        {
                            this.LogTaskMessage(MessageImportance.High, string.Format("File '{0}' is newer then '{1}'", projectFileInfo.Name, artifactFileInfo.Name));
                            doBuild = true;
                        }
                        else
                        {
                            foreach (var file in projectVBP.GetFiles())
                            {
                                this.LogTaskMessage(string.Format("File '{0}', LastWrite: {1}'", file.FullName, file.LastWriteTime));

                                if (file.LastWriteTime > artifactFileInfo.LastWriteTime)
                                {
                                    this.LogTaskMessage(MessageImportance.High, string.Format(CultureInfo.CurrentCulture, "File '{0}' is newer then '{1}'", file.Name, artifactFileInfo.Name));
                                    doBuild = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!doBuild)
                    {
                        this.LogTaskMessage(MessageImportance.High, "Build skipped, because no modifications exists.");
                        return(true);
                    }

                    this.LogTaskMessage("END - Checking for modified files");
                }

                proc.StartInfo.FileName               = this.VB6Path;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError  = true;
                if (string.IsNullOrEmpty(project.GetMetadata("OutDir")))
                {
                    proc.StartInfo.Arguments = @"/MAKE /OUT " + @"""" + project.ItemSpec + ".log" + @""" " + @"""" + project.ItemSpec + @"""";
                }
                else
                {
                    if (!Directory.Exists(project.GetMetadata("OutDir")))
                    {
                        Directory.CreateDirectory(project.GetMetadata("OutDir"));
                    }

                    proc.StartInfo.Arguments = @"/MAKE /OUT " + @"""" + project.ItemSpec + ".log" + @""" " + @"""" + project.ItemSpec + @"""" + " /outdir " + @"""" + project.GetMetadata("OutDir") + @"""";
                }

                // start the process
                this.LogTaskMessage("Running " + proc.StartInfo.FileName + " " + proc.StartInfo.Arguments);

                proc.Start();

                string outputStream = proc.StandardOutput.ReadToEnd();
                if (outputStream.Length > 0)
                {
                    this.LogTaskMessage(outputStream);
                }

                string errorStream = proc.StandardError.ReadToEnd();
                if (errorStream.Length > 0)
                {
                    Log.LogError(errorStream);
                }

                proc.WaitForExit();
                if (proc.ExitCode != 0)
                {
                    Log.LogError("Non-zero exit code from VB6.exe: " + proc.ExitCode);
                    try
                    {
                        using (FileStream myStreamFile = new FileStream(project.ItemSpec + ".log", FileMode.Open))
                        {
                            System.IO.StreamReader myStream = new System.IO.StreamReader(myStreamFile);
                            string myBuffer = myStream.ReadToEnd();
                            Log.LogError(myBuffer);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.LogError(string.Format(CultureInfo.CurrentUICulture, "Unable to open log file: '{0}'. Exception: {1}", project.ItemSpec + ".log", ex.Message));
                    }

                    return(false);
                }

                if (artifactFileInfo != null)
                {
                    var myNow = DateTime.Now;
                    artifactFileInfo.LastWriteTime  = myNow;
                    artifactFileInfo.LastAccessTime = myNow;
                }

                return(true);
            }
        }
예제 #53
0
        public static bool ValidReferenceLibraryForPropertyProvider(ITaskItem referenceLibrary)
        {
            var copyLocal = referenceLibrary.GetMetadata("Private");

            return(String.IsNullOrEmpty(copyLocal) || String.Compare(copyLocal, "false", true) != 0);
        }
        public override bool RunTask()
        {
            var resource_name_case_map = MonoAndroidHelper.LoadResourceCaseMap(ResourceNameCaseMap);
            var acw_map       = MonoAndroidHelper.LoadAcwMapFile(AcwMapFile);
            var customViewMap = MonoAndroidHelper.LoadCustomViewMapFile(BuildEngine4, CustomViewMapFile);
            var processed     = new HashSet <string> ();

            foreach (var kvp in acw_map)
            {
                var key   = kvp.Key;
                var value = kvp.Value;
                if (key == value)
                {
                    continue;
                }
                if (customViewMap.TryGetValue(key, out HashSet <string> resourceFiles))
                {
                    foreach (var file in resourceFiles)
                    {
                        if (processed.Contains(file))
                        {
                            continue;
                        }
                        if (!File.Exists(file))
                        {
                            continue;
                        }
                        var  document = XDocument.Load(file, options: LoadOptions.SetLineInfo);
                        var  e        = document.Root;
                        bool update   = false;
                        foreach (var elem in AndroidResource.GetElements(e).Prepend(e))
                        {
                            update |= TryFixCustomView(elem, acw_map, (level, message) => {
                                ITaskItem resdir = ResourceDirectories?.FirstOrDefault(x => file.StartsWith(x.ItemSpec, StringComparison.OrdinalIgnoreCase)) ?? null;
                                switch (level)
                                {
                                case TraceLevel.Error:
                                    Log.FixupResourceFilenameAndLogCodedError("XA1002", message, file, resdir?.ItemSpec, resource_name_case_map);
                                    break;

                                case TraceLevel.Warning:
                                    Log.FixupResourceFilenameAndLogCodedError("XA1001", message, file, resdir?.ItemSpec, resource_name_case_map);
                                    break;

                                default:
                                    Log.LogDebugMessage(message);
                                    break;
                                }
                            });
                        }
                        foreach (XAttribute a in AndroidResource.GetAttributes(e))
                        {
                            update |= TryFixCustomClassAttribute(a, acw_map);
                            update |= TryFixFragment(a, acw_map);
                        }
                        if (update)
                        {
                            var lastModified = File.GetLastWriteTimeUtc(file);
                            if (document.SaveIfChanged(file))
                            {
                                Log.LogDebugMessage($"Fixed up Custom Views in {file}");
                                File.SetLastWriteTimeUtc(file, lastModified);
                            }
                        }
                        processed.Add(file);
                    }
                }
            }
            var output = new Dictionary <string, ITaskItem> (processed.Count);

            foreach (var file in processed)
            {
                ITaskItem resdir    = ResourceDirectories?.FirstOrDefault(x => file.StartsWith(x.ItemSpec)) ?? null;
                var       hash      = resdir?.GetMetadata("Hash") ?? null;
                var       stamp     = resdir?.GetMetadata("StampFile") ?? null;
                var       filename  = !string.IsNullOrEmpty(hash) ? hash : "compiled";
                var       stampFile = !string.IsNullOrEmpty(stamp) ? stamp : $"{filename}.stamp";
                Log.LogDebugMessage($"{filename} {stampFile}");
                output.Add(file, new TaskItem(Path.GetFullPath(file), new Dictionary <string, string> {
                    { "StampFile", stampFile },
                    { "Hash", filename },
                    { "Resource", resdir?.ItemSpec ?? file },
                }));
            }
            Processed = output.Values.ToArray();
            return(!Log.HasLoggedErrors);
        }
예제 #55
0
 private bool IsTargetPathIncluded(ITaskItem item)
 {
     return(TargetFilePrefixes
            ?.Any(prefix => item.GetMetadata("TargetPath")?.StartsWith(prefix) == true) ?? true);
 }
예제 #56
0
 public static string MSBuildSourceProjectFile(this ITaskItem taskItem) =>
 taskItem.GetMetadata("MSBuildSourceProjectFile");
예제 #57
0
 public KnownFrameworkReference(ITaskItem item)
 {
     _item           = item;
     TargetFramework = NuGetFramework.Parse(item.GetMetadata("TargetFramework"));
 }
예제 #58
0
 public static string FullPath(this ITaskItem taskItem) =>
 taskItem.GetMetadata("FullPath");
예제 #59
0
        private IJobDefinition AddWorkItem(IJobDefinition def, ITaskItem workItem)
        {
            if (!workItem.GetRequiredMetadata(Log, MetadataNames.Identity, out string name))
            {
                return(def);
            }

            if (name.Contains('%'))
            {
                Log.LogWarning($"Work Item named '{name}' contains encoded characters which is not recommended.");
            }

            var cleanedName = Helpers.CleanWorkItemName(name);

            if (name != cleanedName)
            {
                Log.LogWarning($"Work Item named '{name}' contains unsupported characters and has been renamed to '{cleanedName}'.");
            }

            name = cleanedName;

            if (!workItem.GetRequiredMetadata(Log, MetadataNames.Command, out string command))
            {
                return(def);
            }

            Log.LogMessage(MessageImportance.Low, $"Adding work item '{name}'");

            var commands = GetCommands(workItem, command).ToList();

            IWorkItemDefinitionWithPayload wiWithPayload;

            if (commands.Count == 1)
            {
                wiWithPayload = def.DefineWorkItem(name).WithCommand(commands[0]);
                Log.LogMessage(MessageImportance.Low, $"  Command: '{commands[0]}'");
            }
            else
            {
                string commandFile             = _commandPayload.AddCommandFile(commands);
                string helixCorrelationPayload =
                    IsPosixShell ? "$HELIX_CORRELATION_PAYLOAD/" : "%HELIX_CORRELATION_PAYLOAD%\\";
                wiWithPayload = def.DefineWorkItem(name).WithCommand(helixCorrelationPayload + commandFile);
                Log.LogMessage(MessageImportance.Low, $"  Command File: '{commandFile}'");
                foreach (string c in commands)
                {
                    Log.LogMessage(MessageImportance.Low, $"    {c}");
                }
            }

            string payloadDirectory = workItem.GetMetadata(MetadataNames.PayloadDirectory);
            string payloadArchive   = workItem.GetMetadata(MetadataNames.PayloadArchive);
            string payloadUri       = workItem.GetMetadata(MetadataNames.PayloadUri);
            IWorkItemDefinition wi;

            if (!string.IsNullOrEmpty(payloadUri))
            {
                wi = wiWithPayload.WithPayloadUri(new Uri(payloadUri));
                Log.LogMessage(MessageImportance.Low, $"  Uri Payload: '{payloadUri}'");
            }
            else if (!string.IsNullOrEmpty(payloadDirectory))
            {
                wi = wiWithPayload.WithDirectoryPayload(payloadDirectory);
                Log.LogMessage(MessageImportance.Low, $"  Directory Payload: '{payloadDirectory}'");
            }
            else if (!string.IsNullOrEmpty(payloadArchive))
            {
                wi = wiWithPayload.WithArchivePayload(payloadArchive);
                Log.LogMessage(MessageImportance.Low, $"  Archive Payload: '{payloadArchive}'");
            }
            else
            {
                wi = wiWithPayload.WithEmptyPayload();
                Log.LogMessage(MessageImportance.Low, "  Empty Payload");
            }


            string timeoutString = workItem.GetMetadata(MetadataNames.Timeout);

            if (!string.IsNullOrEmpty(timeoutString))
            {
                if (TimeSpan.TryParse(timeoutString, CultureInfo.InvariantCulture, out TimeSpan timeout))
                {
                    wi = wi.WithTimeout(timeout);
                    Log.LogMessage(MessageImportance.Low, $"  Timeout: '{timeout}'");
                }
                else
                {
                    Log.LogWarning($"Timeout value '{timeoutString}' could not be parsed.");
                }
            }
            else
            {
                Log.LogMessage(MessageImportance.Low, "  Default Timeout");
            }

            return(wi.AttachToJob());
        }
예제 #60
0
        public void HarvestFilesFromPackage()
        {
            string pathToPackage = _packageFolders[PackageId];

            var livePackageItems = Files.NullAsEmpty()
                                   .Where(f => IsIncludedExtension(f.GetMetadata("Extension")))
                                   .Select(f => new PackageItem(f));

            var livePackageFiles = new Dictionary <string, PackageItem>(StringComparer.OrdinalIgnoreCase);

            foreach (var livePackageItem in livePackageItems)
            {
                PackageItem existingitem;

                if (livePackageFiles.TryGetValue(livePackageItem.TargetPath, out existingitem))
                {
                    Log.LogError($"Package contains two files with same targetpath: {livePackageItem.TargetPath}, items:{livePackageItem.SourcePath}, {existingitem.SourcePath}.");
                }
                else
                {
                    livePackageFiles.Add(livePackageItem.TargetPath, livePackageItem);
                }
            }

            var harvestedFiles = new List <ITaskItem>();
            var removeFiles    = new List <ITaskItem>();

            // make sure we preserve refs that match desktop assemblies
            var liveDesktopDlls    = livePackageFiles.Values.Where(pi => pi.IsDll && pi.TargetFramework?.Framework == FrameworkConstants.FrameworkIdentifiers.Net);
            var desktopRefVersions = liveDesktopDlls.Where(d => d.IsRef && d.Version != null).Select(d => d.Version);
            var desktopLibVersions = liveDesktopDlls.Where(d => !d.IsRef && d.Version != null).Select(d => d.Version);

            // find desktop assemblies with no matching lib.
            var preserveRefVersion = new HashSet <Version>(desktopLibVersions);

            preserveRefVersion.ExceptWith(desktopRefVersions);

            foreach (var extension in s_includedExtensions)
            {
                foreach (var packageFile in Directory.EnumerateFiles(pathToPackage, $"*{extension}", SearchOption.AllDirectories))
                {
                    string harvestPackagePath = packageFile.Substring(pathToPackage.Length + 1).Replace('\\', '/');

                    // determine if we should include this file from the harvested package

                    // exclude if its specifically set for exclusion
                    if (ShouldExclude(harvestPackagePath))
                    {
                        Log.LogMessage(LogImportance.Low, $"Excluding package path {harvestPackagePath} because it is specifically excluded.");
                        continue;
                    }

                    ITaskItem includeItem = null;
                    if (!IncludeAllPaths && !ShouldInclude(harvestPackagePath, out includeItem))
                    {
                        Log.LogMessage(LogImportance.Low, $"Excluding package path {harvestPackagePath} because it is not included in {nameof(PathsToInclude)}.");
                        continue;
                    }

                    // allow for the harvested item to be moved
                    var remappedTargetPath = includeItem?.GetMetadata("TargetPath");
                    if (!String.IsNullOrEmpty(remappedTargetPath))
                    {
                        harvestPackagePath = remappedTargetPath + '/' + Path.GetFileName(packageFile);
                    }

                    List <string> targetPaths = new List <string>()
                    {
                        harvestPackagePath
                    };

                    var additionalTargetPaths = includeItem?.GetMetadata("AdditionalTargetPath");
                    if (!String.IsNullOrEmpty(additionalTargetPaths))
                    {
                        foreach (var additionalTargetPath in additionalTargetPaths.Split(';'))
                        {
                            if (!String.IsNullOrEmpty(additionalTargetPath))
                            {
                                targetPaths.Add(additionalTargetPath + '/' + Path.GetFileName(packageFile));
                            }
                        }
                    }

                    var assemblyVersion = extension == s_dll?VersionUtility.GetAssemblyVersion(packageFile) : null;

                    PackageItem liveFile = null;

                    foreach (var livePackagePath in targetPaths)
                    {
                        // determine if the harvested file clashes with a live built file
                        // we'll prefer the harvested reference assembly so long as it's the same API
                        // version and not required to match implementation 1:1 as is the case for desktop
                        if (livePackageFiles.TryGetValue(livePackagePath, out liveFile))
                        {
                            // Not a dll, or not a versioned assembly: prefer live built file.
                            if (extension != s_dll || assemblyVersion == null || liveFile.Version == null)
                            {
                                // we don't consider this an error even for explicitly included files
                                Log.LogMessage(LogImportance.Low, $"Preferring live build of package path {livePackagePath} over the asset from last stable package because the file is not versioned.");
                                continue;
                            }

                            // not a ref
                            if (!liveFile.IsRef)
                            {
                                LogSkipIncludedFile(livePackagePath, " because it is a newer implementation.");
                                continue;
                            }

                            // preserve desktop references to ensure bindingRedirects will work.
                            if (liveFile.TargetFramework.Framework == FrameworkConstants.FrameworkIdentifiers.Net)
                            {
                                LogSkipIncludedFile(livePackagePath, " because it is desktop reference.");
                                continue;
                            }

                            // as above but handle the case where a netstandard ref may be used for a desktop impl.
                            if (preserveRefVersion.Contains(liveFile.Version))
                            {
                                LogSkipIncludedFile(livePackagePath, " because it will be applicable for desktop projects.");
                                continue;
                            }

                            // preserve references with a different major.minor version
                            if (assemblyVersion.Major != liveFile.Version.Major ||
                                assemblyVersion.Minor != liveFile.Version.Minor)
                            {
                                LogSkipIncludedFile(livePackagePath, $" because it is a different API version ( {liveFile.Version.Major}.{liveFile.Version.Minor} vs {assemblyVersion.Major}.{assemblyVersion.Minor}.");
                                continue;
                            }

                            // preserve references that specifically set the preserve metadata.
                            bool preserve = false;
                            bool.TryParse(liveFile.OriginalItem.GetMetadata("Preserve"), out preserve);
                            if (preserve)
                            {
                                LogSkipIncludedFile(livePackagePath, " because it set metadata Preserve=true.");
                                continue;
                            }

                            // replace the live file with the harvested one, removing both the live file and PDB from the
                            // file list.
                            Log.LogMessage($"Using reference {livePackagePath} from last stable package {PackageId}/{PackageVersion} rather than the built reference {liveFile.SourcePath} since it is the same API version.  Set <Preserve>true</Preserve> on {liveFile.SourceProject} if you'd like to avoid this..");
                            removeFiles.Add(liveFile.OriginalItem);

                            PackageItem livePdbFile;
                            if (livePackageFiles.TryGetValue(Path.ChangeExtension(livePackagePath, ".pdb"), out livePdbFile))
                            {
                                removeFiles.Add(livePdbFile.OriginalItem);
                            }
                        }
                        else
                        {
                            Log.LogMessage(LogImportance.Low, $"Including {livePackagePath} from last stable package {PackageId}/{PackageVersion}.");
                        }

                        var item = new TaskItem(packageFile);

                        if (liveFile?.OriginalItem != null)
                        {
                            // preserve all the meta-data from the live file that was replaced.
                            liveFile.OriginalItem.CopyMetadataTo(item);
                        }
                        else
                        {
                            if (includeItem != null)
                            {
                                includeItem.CopyMetadataTo(item);
                            }
                            var targetPath = Path.GetDirectoryName(livePackagePath).Replace('\\', '/');
                            item.SetMetadata("TargetPath", targetPath);
                            string targetFramework = GetTargetFrameworkFromPackagePath(targetPath);
                            item.SetMetadata("TargetFramework", targetFramework);
                            // only harvest for non-portable frameworks, matches logic in packaging.targets.
                            bool harvestDependencies = !targetFramework.StartsWith("portable-");
                            item.SetMetadata("HarvestDependencies", harvestDependencies.ToString());
                            item.SetMetadata("IsReferenceAsset", IsReferencePackagePath(targetPath).ToString());
                        }

                        if (assemblyVersion != null)
                        {
                            // overwrite whatever metadata may have been copied from the live file.
                            item.SetMetadata("AssemblyVersion", assemblyVersion.ToString());
                        }

                        item.SetMetadata("HarvestedFrom", $"{PackageId}/{PackageVersion}/{harvestPackagePath}");

                        harvestedFiles.Add(item);
                    }
                }
            }

            HarvestedFiles = harvestedFiles.ToArray();

            if (_pathsNotIncluded != null)
            {
                foreach (var pathNotIncluded in _pathsNotIncluded)
                {
                    Log.LogError($"Path '{pathNotIncluded}' was specified in {nameof(PathsToInclude)} but was not found in the package {PackageId}/{PackageVersion}.");
                }
            }

            if (Files != null)
            {
                UpdatedFiles = Files.Except(removeFiles).ToArray();
            }
        }