private static void ReportCopyToPublishDirectoryItems( ProjectInstance projectInstance, string itemName, string publishDir, ProjectPredictionReporter predictionReporter) { foreach (ProjectItemInstance item in projectInstance.GetItems(itemName)) { var copyToPublishDirectoryValue = item.GetMetadataValue(CopyToPublishDirectoryMetadataName); if (copyToPublishDirectoryValue.Equals("Always", StringComparison.OrdinalIgnoreCase) || copyToPublishDirectoryValue.Equals("PreserveNewest", StringComparison.OrdinalIgnoreCase)) { // The item will be relative to the project instance passed in, not the current project instance, so make the path absolute. predictionReporter.ReportInputFile(Path.Combine(projectInstance.Directory, item.EvaluatedInclude)); if (!string.IsNullOrEmpty(publishDir)) { string targetPath = item.GetTargetPath(); if (!string.IsNullOrEmpty(targetPath)) { predictionReporter.ReportOutputFile(Path.Combine(publishDir, targetPath)); } } } } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // The symbols file as output directly from the compiler. foreach (ProjectItemInstance item in projectInstance.GetItems(DebugSymbolsIntermediatePathItemName)) { predictionReporter.ReportOutputFile(item.EvaluatedInclude); } // CopyFilesToOutputDirectory copies @(_DebugSymbolsIntermediatePath) items to the output directory using a different item group. foreach (ProjectItemInstance item in projectInstance.GetItems(DebugSymbolsOutputPathItemName)) { predictionReporter.ReportOutputFile(item.EvaluatedInclude); } }
public void PredictInputsAndOutputs(ProjectGraphNode projectGraphNode, ProjectPredictionReporter predictionReporter) { foreach (ProjectGraphNode dependency in projectGraphNode.ProjectReferences) { var dependencyDir = dependency.ProjectInstance.Directory; foreach (string item in _inputFiles) { predictionReporter.ReportInputFile(Path.GetFullPath(Path.Combine(dependencyDir, item))); } foreach (string item in _inputDirectories) { predictionReporter.ReportInputDirectory(Path.GetFullPath(Path.Combine(dependencyDir, item))); } foreach (string item in _outputFiles) { predictionReporter.ReportOutputFile(Path.GetFullPath(Path.Combine(dependencyDir, item))); } foreach (string item in _outputDirectories) { predictionReporter.ReportOutputDirectory(Path.GetFullPath(Path.Combine(dependencyDir, item))); } } }
private void ReportOutputs(ProjectPredictionReporter reporter, ProjectItemInstance masmItem) { reporter.ReportOutputFile(masmItem.GetMetadataValue(ObjectFileNameMetadata)); string assembledCodeListingFile = masmItem.GetMetadataValue(AssembledCodeListingFileMetadata); if (!string.IsNullOrWhiteSpace(assembledCodeListingFile)) { reporter.ReportOutputFile(assembledCodeListingFile); } string browseFile = masmItem.GetMetadataValue(BrowseFileMetadata); if (!string.IsNullOrWhiteSpace(browseFile)) { reporter.ReportOutputFile(browseFile); } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // The documentation file as output directly from the compiler. // Note that this item generally has exactly one item which is the value of $(DocumentationFile), // but this item is the one that's actually used so we'll use ti here too since it's included statically. foreach (ProjectItemInstance item in projectInstance.GetItems(DocFileItemItemName)) { predictionReporter.ReportOutputFile(item.EvaluatedInclude); } // CopyFilesToOutputDirectory copies @(DocFileItem) items to the output directory using a different item group. foreach (ProjectItemInstance item in projectInstance.GetItems(FinalDocFileItemName)) { predictionReporter.ReportOutputFile(item.EvaluatedInclude); } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // The compiled ref assembly as output directly from the compiler. foreach (ProjectItemInstance item in projectInstance.GetItems(IntermediateRefAssemblyItemName)) { predictionReporter.ReportOutputFile(item.EvaluatedInclude); } // CopyFilesToOutputDirectory copies @(IntermediateRefAssembly) items to the output directory. // It uses $(TargetRefPath) directly rather than an item. string targetRefPath = projectInstance.GetPropertyValue(TargetRefPathPropertyName); if (!string.IsNullOrWhiteSpace(targetRefPath)) { predictionReporter.ReportOutputFile(targetRefPath); } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { string outDir = projectInstance.GetPropertyValue(OutDirPropertyName); // The compiled assembly as output directly from the compiler. foreach (ProjectItemInstance item in projectInstance.GetItems(IntermediateAssemblyItemName)) { var intermediateAssembly = item.EvaluatedInclude; predictionReporter.ReportOutputFile(intermediateAssembly); // CopyFilesToOutputDirectory copies @(IntermediateAssembly) items to the output directory. if (!string.IsNullOrWhiteSpace(outDir)) { predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(intermediateAssembly))); } } }
/// <inheritdoc/> public void PredictInputsAndOutputs(ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // This predictor only applies when StyleCop exists and is enabled. if (!projectInstance.Targets.ContainsKey(StyleCopTargetName) || projectInstance.GetPropertyValue(StyleCopEnabledPropertyName).Equals("false", StringComparison.OrdinalIgnoreCase)) { return; } // Find the StyleCop settings file as an input. If the override settings file is specified and valid, // it's used. Else fall back to finding the project settings file. Note that the validation or lack thereof // mimics what StyleCop actually does. string styleCopSettingsFile = TryGetOverrideSettingsFile(projectInstance, out string styleCopOverrideSettingsFile) ? styleCopOverrideSettingsFile : GetProjectSettingsFile(projectInstance.Directory); if (!string.IsNullOrEmpty(styleCopSettingsFile)) { predictionReporter.ReportInputFile(styleCopSettingsFile); } // For Completeness we should consider Compile items as well since they're passed to StyleCop, but in practice another predictor will take care of that. // StyleCop addins as input directories foreach (ProjectItemInstance item in projectInstance.GetItems(StyleCopAdditionalAddinPathsItemName)) { string addinPath = item.GetMetadataValue("FullPath"); string expandedAddinPath = Environment.ExpandEnvironmentVariables(addinPath); if (Directory.Exists(expandedAddinPath)) { predictionReporter.ReportInputDirectory(expandedAddinPath); } } // StyleCop violations file as an output string styleCopOutputFile = projectInstance.GetPropertyValue(StyleCopOutputFilePropertyName); if (!string.IsNullOrEmpty(styleCopOutputFile)) { predictionReporter.ReportOutputFile(styleCopOutputFile); } // When StyleCopCacheResults is true, a StyleCop.Cache file is written adjacent to the project. // Currently we want to avoid predicting this as predicting outputs to non-output directories generally leads to problems in the consumers of this library. // If the need for absolute completeness arises, it should be added and those consumers will just need to deal. }
private static void ProcessFile( string sourceFile, string fileName, string[] destinationFolders, string destinationSubDirectory, ProjectPredictionReporter predictionReporter) { // Inputs predictionReporter.ReportInputFile(sourceFile); // Outputs foreach (string destination in destinationFolders) { string destinationFile = !string.IsNullOrEmpty(destinationSubDirectory) ? Path.Combine(destination, destinationSubDirectory, fileName) : Path.Combine(destination, fileName); predictionReporter.ReportOutputFile(destinationFile); } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { string outDir = projectInstance.GetPropertyValue(OutDirPropertyName); foreach (ProjectItemInstance item in projectInstance.GetItems(ContentItemName)) { predictionReporter.ReportInputFile(item.EvaluatedInclude); if (!string.IsNullOrEmpty(outDir) && item.ShouldCopyToOutputDirectory()) { string targetPath = item.GetTargetPath(); if (!string.IsNullOrEmpty(targetPath)) { predictionReporter.ReportOutputFile(Path.Combine(outDir, targetPath)); } } } }
public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { foreach (var item in _inputFiles) { predictionReporter.ReportInputFile(item); } foreach (var item in _inputDirectories) { predictionReporter.ReportInputDirectory(item); } foreach (var item in _outputFiles) { predictionReporter.ReportOutputFile(item); } foreach (var item in _outputDirectories) { predictionReporter.ReportOutputDirectory(item); } }
private static void ReportCopyToOutputDirectoryItemsAsInputs( ProjectInstance projectInstance, string itemName, string outDir, ProjectPredictionReporter predictionReporter) { foreach (ProjectItemInstance item in projectInstance.GetItems(itemName)) { if (item.ShouldCopyToOutputDirectory()) { // The item will be relative to the project instance passed in, not the current project instance, so make the path absolute. predictionReporter.ReportInputFile(Path.Combine(projectInstance.Directory, item.EvaluatedInclude)); if (!string.IsNullOrEmpty(outDir)) { string targetPath = item.GetTargetPath(); if (!string.IsNullOrEmpty(targetPath)) { predictionReporter.ReportOutputFile(Path.Combine(outDir, targetPath)); } } } } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { List <string> configFiles = FindConfigFiles(projectInstance); foreach (string configFile in configFiles) { string configFileFullPath = Path.Combine(projectInstance.Directory, configFile); string configFileContent = File.ReadAllText(configFileFullPath); bool isTsConfig = Path.GetFileName(configFile).Equals(TsConfigFileName, PathComparer.Comparison); TsConfig tsConfig; try { tsConfig = JsonSerializer.Deserialize <TsConfig>(configFileContent, _jsonSerializerOptions); } catch (JsonException) { // Ignore invalid config files continue; } string configFileDir = Path.GetDirectoryName(configFileFullPath); tsConfig.ApplyDefaults(); if (tsConfig.Files != null) { foreach (string file in tsConfig.Files) { string fileFullPath = PathUtilities.NormalizePath(Path.Combine(configFileDir, file)); predictionReporter.ReportInputFile(fileFullPath); } } // Reuse MSBuild's globbing logic as it should match what tsc does. if (tsConfig.Include != null) { var directoriesToEnumerate = new Queue <string>(); var includeGlobs = new MSBuildGlob[tsConfig.Include.Count]; for (var i = 0; i < tsConfig.Include.Count; i++) { string include = tsConfig.Include[i]; MSBuildGlob includeGlob = MSBuildGlob.Parse(configFileDir, include); directoriesToEnumerate.Enqueue(includeGlob.FixedDirectoryPart); includeGlobs[i] = includeGlob; } var excludeGlobs = new MSBuildGlob[tsConfig.Exclude.Count]; for (var i = 0; i < tsConfig.Exclude.Count; i++) { string exclude = tsConfig.Exclude[i]; // Handle the case where just a folder name is used as an exclude value if (exclude.IndexOf('*', StringComparison.Ordinal) == -1) { exclude += "/**"; } excludeGlobs[i] = MSBuildGlob.Parse(configFileDir, exclude); } var finalGlob = new MSBuildGlobWithGaps(new CompositeGlob(includeGlobs), excludeGlobs); var visitedDirectories = new HashSet <string>(PathComparer.Instance); while (directoriesToEnumerate.Count > 0) { string directoryToEnumerate = directoriesToEnumerate.Dequeue(); // In case the initial globs has parent/child relationships if (!visitedDirectories.Add(directoryToEnumerate)) { continue; } // Some globs might point to non-existent paths. if (!Directory.Exists(directoryToEnumerate)) { continue; } foreach (string file in Directory.EnumerateFiles(directoryToEnumerate, "*", SearchOption.TopDirectoryOnly)) { if (finalGlob.IsMatch(file)) { predictionReporter.ReportInputFile(file); } } foreach (string directory in Directory.EnumerateDirectories(directoryToEnumerate, "*", SearchOption.TopDirectoryOnly)) { directoriesToEnumerate.Enqueue(directory); } } } if (isTsConfig && tsConfig.CompilerOptions != null) { if (!string.IsNullOrEmpty(tsConfig.CompilerOptions.OutFile)) { string outFileFullPath = PathUtilities.NormalizePath(Path.Combine(configFileDir, tsConfig.CompilerOptions.OutFile)); predictionReporter.ReportOutputFile(outFileFullPath); } if (!string.IsNullOrEmpty(tsConfig.CompilerOptions.OutDir)) { string outDirFullPath = PathUtilities.NormalizePath(Path.Combine(configFileDir, tsConfig.CompilerOptions.OutDir)); predictionReporter.ReportOutputDirectory(outDirFullPath); } } } }
/// <inheritdoc/> public void PredictInputsAndOutputs(ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // Non-ClickOnce applications use $(Win32Manifest) as an input to CSC, and the _SetEmbeddedWin32ManifestProperties target sets $(Win32Manifest) = $(ApplicationManifest). // ClickOnce applications don't use $(Win32Manifest) but do use $(ApplicationManifest) as an input anyway, so just always consider it an input. string applicationManifest = projectInstance.GetPropertyValue(ApplicationManifestPropertyName); if (!string.IsNullOrEmpty(applicationManifest)) { predictionReporter.ReportInputFile(applicationManifest); } // ClickOnce applications if (projectInstance.GetPropertyValue(GenerateClickOnceManifestsPropertyName).Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { // $(_DeploymentBaseManifest) is an input to the GenerateApplicationManifest target/task, which in the _SetExternalWin32ManifestProperties // target is defined as $(ApplicationManifest) if it's set, which we've already predicted as an input above. if (string.IsNullOrEmpty(applicationManifest)) { // If $(ApplicationManifest) isn't set, $(_DeploymentBaseManifest) is set to @(_DeploymentBaseManifestWithTargetPath), which in the AssignTargetPaths target // is set to @(BaseApplicationManifest) if any or @(None) items with the '.manifest' extension otherwise. var baseApplicationManifests = projectInstance.GetItems(BaseApplicationManifestItemName); if (baseApplicationManifests.Count > 0) { foreach (ProjectItemInstance item in baseApplicationManifests) { predictionReporter.ReportInputFile(item.EvaluatedInclude); } } else { var none = projectInstance.GetItems(NoneItemName); foreach (ProjectItemInstance item in none) { if (item.EvaluatedInclude.EndsWith(ManifestExtension, StringComparison.OrdinalIgnoreCase)) { predictionReporter.ReportInputFile(item.EvaluatedInclude); } } } } // Application manifest var applicationManifestName = projectInstance.GetPropertyValue(OutputTypePropertyName).Equals("library", StringComparison.OrdinalIgnoreCase) ? "Native." + projectInstance.GetPropertyValue(AssemblyNamePropertyName) + ManifestExtension : projectInstance.GetPropertyValue(TargetFileNamePropertyName) + ManifestExtension; predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(IntermediateOutputPathPropertyName) + applicationManifestName); predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(OutDirPropertyName) + applicationManifestName); // Deployment manifest var deploymentManifestName = projectInstance.GetPropertyValue(HostInBrowserPropertyName).Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) ? projectInstance.GetPropertyValue(AssemblyNamePropertyName) + ".xbap" : projectInstance.GetPropertyValue(AssemblyNamePropertyName) + ".application"; predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(IntermediateOutputPathPropertyName) + deploymentManifestName); predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(OutDirPropertyName) + deploymentManifestName); // Intermediate Trust info file if (!string.IsNullOrEmpty(projectInstance.GetPropertyValue(TargetZonePropertyName))) { predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(IntermediateOutputPathPropertyName) + projectInstance.GetPropertyValue(TargetFileNamePropertyName) + ".TrustInfo.xml"); } } }
/// <inheritdoc/> public void PredictInputsAndOutputs( ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter) { // This is based on NuGet.Build.Tasks.Pack.targets and GetPackOutputItemsTask // See: https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets // See: https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks.Pack/GetPackOutputItemsTask.cs var generatePackageOnBuild = projectInstance.GetPropertyValue(GeneratePackageOnBuildPropertyName); if (!generatePackageOnBuild.Equals("true", StringComparison.OrdinalIgnoreCase)) { return; } var packageId = projectInstance.GetPropertyValue(PackageIdPropertyName); var packageVersion = projectInstance.GetPropertyValue(PackageVersionPropertyName); var packageOutputPath = projectInstance.GetPropertyValue(PackageOutputPathPropertyName); var nuspecOutputPath = projectInstance.GetPropertyValue(NuspecOutputPathPropertyName); var includeSource = projectInstance.GetPropertyValue(IncludeSourcePropertyName).Equals("true", StringComparison.OrdinalIgnoreCase); var includeSymbols = projectInstance.GetPropertyValue(IncludeSymbolsPropertyName).Equals("true", StringComparison.OrdinalIgnoreCase); var outputFileNamesWithoutVersion = projectInstance.GetPropertyValue(OutputFileNamesWithoutVersionPropertyName).Equals("true", StringComparison.OrdinalIgnoreCase); var symbolPackageFormat = projectInstance.GetPropertyValue(SymbolPackageFormatPropertyName); // PackageOutputPath defaults to OutputPath in the _CalculateInputsOutputsForPack target, not statically. if (string.IsNullOrEmpty(packageOutputPath)) { packageOutputPath = projectInstance.GetPropertyValue(OutputPathPropertyName); } // All params are effectively required if (!string.IsNullOrEmpty(packageId) && !string.IsNullOrEmpty(packageVersion) && !string.IsNullOrEmpty(packageOutputPath) && !string.IsNullOrEmpty(nuspecOutputPath) && !string.IsNullOrEmpty(symbolPackageFormat)) { var fileBaseName = outputFileNamesWithoutVersion ? packageId : $"{packageId}.{packageVersion}"; // Nuspec files can also be provided instead of generated, in which case we should treat it like an input, not an output. var nuspecFile = projectInstance.GetPropertyValue(NuspecFilePropertyName); predictionReporter.ReportOutputFile(Path.Combine(packageOutputPath, fileBaseName + ".nupkg")); if (string.IsNullOrEmpty(nuspecFile)) { predictionReporter.ReportOutputFile(Path.Combine(nuspecOutputPath, fileBaseName + ".nuspec")); } else { predictionReporter.ReportInputFile(nuspecFile); } if (includeSource || includeSymbols) { predictionReporter.ReportOutputFile(Path.Combine(packageOutputPath, fileBaseName + (symbolPackageFormat.Equals("snupkg", StringComparison.OrdinalIgnoreCase) ? ".snupkg" : ".symbols.nupkg"))); if (string.IsNullOrEmpty(nuspecFile)) { predictionReporter.ReportOutputFile(Path.Combine(nuspecOutputPath, fileBaseName + ".symbols.nuspec")); } } } }