Example #1
0
        public async Task BuildSolution(string target)
        {
            State = AppState.Building;
            BuildStarted?.Invoke(this, EventArgs.Empty);

            var results = new List <Microsoft.Build.Execution.BuildResult>();

            await Task.Factory.StartNew(() =>
            {
                ClearOutput();

                var msbuild = Microsoft.Build.Execution.BuildManager.DefaultBuildManager;
                var projs   = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection;

                projs.AddToolset(new Microsoft.Build.Evaluation.Toolset("Current", Path.Combine(DotNetInfo.SdkPath, DotNetInfo.SdkVersion), projs, Path.Combine(DotNetInfo.SdkPath, DotNetInfo.SdkVersion)));

                var globalProperties = new Dictionary <string, string>()
                {
                    { "Configuration", SelectedConfiguration },
                    { "PlatformTarget", SelectedPlatform }
                };

                foreach (var proj in this.Workspace.CurrentSolution.Projects)
                {
                    projs.LoadProject(proj.FilePath);
                }

                var parameters = new Microsoft.Build.Execution.BuildParameters(projs);

                var loggers = new List <Microsoft.Build.Framework.ILogger>();
                var cl      = new Microsoft.Build.Logging.ConsoleLogger(Microsoft.Build.Framework.LoggerVerbosity.Normal, new Microsoft.Build.Logging.WriteHandler((s) => MSBuildLog(s)), new Microsoft.Build.Logging.ColorSetter((c) => MSBuildLogSetColor(c)), new Microsoft.Build.Logging.ColorResetter(() => MSBuildLogResetColor()));

                loggers.Add(cl);

                parameters.Loggers = loggers;

                msbuild.BeginBuild(parameters);

                var targets = new[] { target };

                if (!target.Equals("restore", StringComparison.OrdinalIgnoreCase) && !target.Equals("clean", StringComparison.OrdinalIgnoreCase))
                {
                    targets = new[] { "restore", target };
                }

                foreach (var p in Workspace.ProjectInstances)
                {
                    var pinstance   = new Microsoft.Build.Execution.ProjectInstance(p.FullPath, globalProperties, projs.DefaultToolsVersion, projs);
                    var requestData = new Microsoft.Build.Execution.BuildRequestData(pinstance, targets);

                    results.Add(msbuild.BuildRequest(requestData));
                }

                msbuild.EndBuild();
            });

            State = AppState.SolutionReady;
            BuildFinished?.Invoke(this, EventArgs.Empty);
            OnBuildFinished(results);
        }
Example #2
0
 public static IEnumerable <ProjectFileReference> GetProjectReferences(
     this MSB.Execution.ProjectInstance executedProject
     ) =>
 executedProject
 .GetItems(ItemNames.ProjectReference)
 .Where(i => i.ReferenceOutputAssemblyIsTrue())
 .Select(CreateProjectFileReference);
Example #3
0
        private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance project)
        {
            var commandLineArgs = GetCommandLineArgs(project);

            var outputFilePath = project.ReadPropertyString(PropertyNames.TargetPath);

            if (!RoslynString.IsNullOrWhiteSpace(outputFilePath))
            {
                outputFilePath = GetAbsolutePathRelativeToProject(outputFilePath);
            }

            var outputRefFilePath = project.ReadPropertyString(PropertyNames.TargetRefPath);

            if (!RoslynString.IsNullOrWhiteSpace(outputRefFilePath))
            {
                outputRefFilePath = GetAbsolutePathRelativeToProject(outputRefFilePath);
            }

            // Right now VB doesn't have the concept of "default namespace". But we conjure one in workspace
            // by assigning the value of the project's root namespace to it. So various feature can choose to
            // use it for their own purpose.
            // In the future, we might consider officially exposing "default namespace" for VB project
            // (e.g. through a <defaultnamespace> msbuild property)
            var defaultNamespace = project.ReadPropertyString(PropertyNames.RootNamespace) ?? string.Empty;

            var targetFramework = project.ReadPropertyString(PropertyNames.TargetFramework);

            if (RoslynString.IsNullOrWhiteSpace(targetFramework))
            {
                targetFramework = null;
            }

            var docs = project.GetDocuments()
                       .Where(IsNotTemporaryGeneratedFile)
                       .Select(MakeDocumentFileInfo)
                       .ToImmutableArray();

            var additionalDocs = project.GetAdditionalFiles()
                                 .Select(MakeNonSourceFileDocumentFileInfo)
                                 .ToImmutableArray();

            var analyzerConfigDocs = project.GetEditorConfigFiles()
                                     .Select(MakeNonSourceFileDocumentFileInfo)
                                     .ToImmutableArray();

            return(ProjectFileInfo.Create(
                       Language,
                       project.FullPath,
                       outputFilePath,
                       outputRefFilePath,
                       defaultNamespace,
                       targetFramework,
                       commandLineArgs,
                       docs,
                       additionalDocs,
                       analyzerConfigDocs,
                       project.GetProjectReferences().ToImmutableArray(),
                       Log));
        }
Example #4
0
 protected IEnumerable <ProjectFileReference> GetProjectReferences(MSB.Execution.ProjectInstance executedProject)
 {
     return(executedProject
            .GetItems("ProjectReference")
            .Where(i => !string.Equals(
                       i.GetMetadataValue("ReferenceOutputAssembly"),
                       bool.FalseString,
                       StringComparison.OrdinalIgnoreCase))
            .Select(CreateProjectFileReference));
 }
            private static RuleSet ResolveRulesetIfAny(MSB.Execution.ProjectInstance projectInstance)
            {
                var rulesetIfAny = projectInstance.Properties.FirstOrDefault(x => x.Name == "ResolvedCodeAnalysisRuleSet");

                if (rulesetIfAny != null)
                {
                    return(RuleSet.LoadEffectiveRuleSetFromFile(Path.Combine(projectInstance.Directory, rulesetIfAny.EvaluatedValue)));
                }

                return(null);
            }
Example #6
0
 public ProjectLoadedEventArgs(
     ProjectId id,
     MSB.Execution.ProjectInstance projectInstance,
     ImmutableArray <MSBuildDiagnostic> diagnostics,
     bool isReload)
 {
     Id = id;
     ProjectInstance = projectInstance;
     Diagnostics     = diagnostics;
     IsReload        = isReload;
 }
        /// <summary>
        /// Read the .csproj file using Microsoft Build.
        /// This occasionally fails if the project file is incompatible for some reason,
        /// and there seems to be no way to make it succeed. Fails on Linux.
        /// </summary>
        /// <param name="filename">The file to read.</param>
        private void ReadMsBuildProject(FileInfo filename)
        {
            var msbuildProject = new Microsoft.Build.Execution.ProjectInstance(filename.FullName);

            references = msbuildProject.
                         Items.
                         Where(item => item.ItemType == "Reference").
                         Select(item => item.EvaluatedInclude).
                         ToArray();

            csFiles = msbuildProject.Items
                      .Where(item => item.ItemType == "Compile")
                      .Select(item => item.GetMetadataValue("FullPath"))
                      .Where(fn => fn.EndsWith(".cs"))
                      .ToArray();
        }
Example #8
0
        protected string GetItemString(MSB.Execution.ProjectInstance executedProject, string itemType)
        {
            string text = "";

            foreach (var item in executedProject.GetItems(itemType))
            {
                if (text.Length > 0)
                {
                    text = text + " ";
                }

                text = text + item.EvaluatedInclude;
            }

            return(text);
        }
Example #9
0
        private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance project)
        {
            var commandLineArgs = GetCommandLineArgs(project);

            var outputFilePath = project.ReadPropertyString(PropertyNames.TargetPath);

            if (!string.IsNullOrWhiteSpace(outputFilePath))
            {
                outputFilePath = GetAbsolutePathRelativeToProject(outputFilePath);
            }

            var outputRefFilePath = project.ReadPropertyString(PropertyNames.TargetRefPath);

            if (!string.IsNullOrWhiteSpace(outputRefFilePath))
            {
                outputRefFilePath = GetAbsolutePathRelativeToProject(outputRefFilePath);
            }

            var targetFramework = project.ReadPropertyString(PropertyNames.TargetFramework);

            if (string.IsNullOrWhiteSpace(targetFramework))
            {
                targetFramework = null;
            }

            var docs = project.GetDocuments()
                       .Where(IsNotTemporaryGeneratedFile)
                       .Select(MakeDocumentFileInfo)
                       .ToImmutableArray();

            var additionalDocs = project.GetAdditionalFiles()
                                 .Select(MakeAdditionalDocumentFileInfo)
                                 .ToImmutableArray();

            return(ProjectFileInfo.Create(
                       Language,
                       project.FullPath,
                       outputFilePath,
                       outputRefFilePath,
                       targetFramework,
                       commandLineArgs,
                       docs,
                       additionalDocs,
                       project.GetProjectReferences().ToImmutableArray(),
                       Log));
        }
 public ProjectLoadedEventArgs(
     ProjectId id,
     MSB.Execution.ProjectInstance projectInstance,
     ImmutableArray <MSBuildDiagnostic> diagnostics,
     bool isReload,
     bool projectIdIsDefinedInSolution,
     ImmutableArray <string> sourceFiles,
     IEnumerable <string> references = null)
 {
     Id = id;
     ProjectInstance = projectInstance;
     Diagnostics     = diagnostics;
     IsReload        = isReload;
     ProjectIdIsDefinedInSolution = projectIdIsDefinedInSolution;
     References  = references;
     SourceFiles = sourceFiles;
 }
Example #11
0
        public static string ReadItemsAsString(this MSB.Execution.ProjectInstance executedProject, string itemType)
        {
            var pooledBuilder = PooledStringBuilder.GetInstance();
            var builder       = pooledBuilder.Builder;

            foreach (var item in executedProject.GetItems(itemType))
            {
                if (builder.Length > 0)
                {
                    builder.Append(" ");
                }

                builder.Append(item.EvaluatedInclude);
            }

            return(pooledBuilder.ToStringAndFree());
        }
Example #12
0
        private ImmutableArray <string> GetCommandLineArgs(MSB.Execution.ProjectInstance project)
        {
            var commandLineArgs = GetCompilerCommandLineArgs(project)
                                  .Select(item => item.ItemSpec)
                                  .ToImmutableArray();

            if (commandLineArgs.Length == 0)
            {
                // We didn't get any command-line args, which likely means that the build
                // was not successful. In that case, try to read the command-line args from
                // the ProjectInstance that we have. This is a best effort to provide something
                // meaningful for the user, though it will likely be incomplete.
                commandLineArgs = ReadCommandLineArgs(project);
            }

            return(commandLineArgs);
        }
Example #13
0
        protected string ReadPropertyString(MSB.Execution.ProjectInstance executedProject, string executedPropertyName, string evaluatedPropertyName)
        {
            var executedProperty = executedProject.GetProperty(executedPropertyName);

            if (executedProperty != null)
            {
                return(executedProperty.EvaluatedValue);
            }

            var evaluatedProperty = _loadedProject.GetProperty(evaluatedPropertyName);

            if (evaluatedProperty != null)
            {
                return(evaluatedProperty.EvaluatedValue);
            }

            return(null);
        }
Example #14
0
        /// <summary>
        /// Read the .csproj file using Microsoft Build.
        /// This occasionally fails if the project file is incompatible for some reason,
        /// and there seems to be no way to make it succeed. Fails on Linux.
        /// </summary>
        /// <param name="filename">The file to read.</param>
        private static (string[] csFiles, string[] references, string[] projectReferences) ReadMsBuildProject(FileInfo filename)
        {
            var msbuildProject = new Microsoft.Build.Execution.ProjectInstance(filename.FullName);

            var references = msbuildProject.Items
                             .Where(item => item.ItemType == "Reference")
                             .Select(item => item.EvaluatedInclude)
                             .ToArray();

            var projectReferences = msbuildProject.Items
                                    .Where(item => item.ItemType == "ProjectReference")
                                    .Select(item => item.EvaluatedInclude)
                                    .ToArray();

            var csFiles = msbuildProject.Items
                          .Where(item => item.ItemType == "Compile")
                          .Select(item => item.GetMetadataValue("FullPath"))
                          .Where(fn => fn.EndsWith(".cs"))
                          .ToArray();

            return(csFiles, references, projectReferences);
        }
 public ProjectLoadedEventArgs(
     ProjectId id,
     MSB.Evaluation.Project project,
     Guid sessionId,
     MSB.Execution.ProjectInstance projectInstance,
     ImmutableArray <MSBuildDiagnostic> diagnostics,
     bool isReload,
     bool projectIdIsDefinedInSolution,
     ImmutableArray <string> sourceFiles,
     SemanticVersion sdkVersion,
     IEnumerable <string> references = null)
 {
     Id              = id;
     Project         = project;
     SessionId       = sessionId;
     ProjectInstance = projectInstance;
     Diagnostics     = diagnostics;
     IsReload        = isReload;
     ProjectIdIsDefinedInSolution = projectIdIsDefinedInSolution;
     References  = references;
     SourceFiles = sourceFiles;
     SdkVersion  = sdkVersion;
 }
Example #16
0
 public static IEnumerable <MSB.Framework.ITaskItem> GetDocuments(
     this MSB.Execution.ProjectInstance executedProject
     ) => executedProject.GetItems(ItemNames.Compile);
Example #17
0
        private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance project)
        {
            var commandLineArgs = GetCommandLineArgs(project);

            var outputFilePath = project.ReadPropertyString(PropertyNames.TargetPath);

            if (!string.IsNullOrWhiteSpace(outputFilePath))
            {
                outputFilePath = GetAbsolutePathRelativeToProject(outputFilePath);
            }

            var outputRefFilePath = project.ReadPropertyString(PropertyNames.TargetRefPath);

            if (!string.IsNullOrWhiteSpace(outputRefFilePath))
            {
                outputRefFilePath = GetAbsolutePathRelativeToProject(outputRefFilePath);
            }

            // Get the default namespace for C# project, which is a C# only concept at the moment.
            // We need the language check because "rootnamespace" property is also used in VB for
            // completely different purpose.
            string defaultNamespace = null;

            if (Language == LanguageNames.CSharp)
            {
                defaultNamespace = project.ReadPropertyString(PropertyNames.RootNamespace);
                if (string.IsNullOrWhiteSpace(defaultNamespace))
                {
                    defaultNamespace = string.Empty;
                }
            }

            var targetFramework = project.ReadPropertyString(PropertyNames.TargetFramework);

            if (string.IsNullOrWhiteSpace(targetFramework))
            {
                targetFramework = null;
            }

            var docs = project.GetDocuments()
                       .Where(IsNotTemporaryGeneratedFile)
                       .Select(MakeDocumentFileInfo)
                       .ToImmutableArray();

            var additionalDocs = project.GetAdditionalFiles()
                                 .Select(MakeAdditionalDocumentFileInfo)
                                 .ToImmutableArray();

            return(ProjectFileInfo.Create(
                       Language,
                       project.FullPath,
                       outputFilePath,
                       outputRefFilePath,
                       defaultNamespace,
                       targetFramework,
                       commandLineArgs,
                       docs,
                       additionalDocs,
                       project.GetProjectReferences().ToImmutableArray(),
                       Log));
        }
Example #18
0
            public static ProjectData Create(string projectFilePath, MSB.Execution.ProjectInstance projectInstance, MSB.Evaluation.Project project)
            {
                var projectFolderPath = Path.GetDirectoryName(projectFilePath);

                var guid                   = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
                var name                   = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName           = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath             = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath             = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
                var intermediateOutputPath = projectInstance.GetPropertyValue(PropertyNames.IntermediateOutputPath);
                var projectAssetsFile      = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);
                var configuration          = projectInstance.GetPropertyValue(PropertyNames.Configuration);
                var platform               = projectInstance.GetPropertyValue(PropertyNames.Platform);
                var defaultNamespace       = projectInstance.GetPropertyValue(PropertyNames.RootNamespace);

                var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = projectInstance.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var checkForOverflowUnderflow = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.CheckForOverflowUnderflow), defaultValue: false);
                var outputKind                     = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
                var nullableContextOptions         = PropertyConverter.ToNullableContextOptions(projectInstance.GetPropertyValue(PropertyNames.Nullable));
                var documentationFile              = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames        = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds        = PropertyConverter.ToSuppressedDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
                var warningsAsErrors               = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.WarningsAsErrors), ',');
                var warningsNotAsErrors            = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.WarningsNotAsErrors), ',');
                var signAssembly                   = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var treatWarningsAsErrors          = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.TreatWarningsAsErrors), defaultValue: false);
                var runAnalyzers                   = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.RunAnalyzers), defaultValue: true);
                var runAnalyzersDuringLiveAnalysis = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.RunAnalyzersDuringLiveAnalysis), defaultValue: true);
                var assemblyOriginatorKeyFile      = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

                var ruleset = ResolveRulesetIfAny(projectInstance);

                var sourceFiles = GetFullPaths(
                    projectInstance.GetItems(ItemNames.Compile), filter: FileNameIsNotGenerated);

                var projectReferences       = ImmutableArray.CreateBuilder <string>();
                var projectReferenceAliases = ImmutableDictionary.CreateBuilder <string, string>();

                var references       = ImmutableArray.CreateBuilder <string>();
                var referenceAliases = ImmutableDictionary.CreateBuilder <string, string>();

                foreach (var referencePathItem in projectInstance.GetItems(ItemNames.ReferencePath))
                {
                    var referenceSourceTarget = referencePathItem.GetMetadataValue(MetadataNames.ReferenceSourceTarget);
                    var aliases = referencePathItem.GetMetadataValue(MetadataNames.Aliases);

                    // If this reference came from a project reference, count it as such. We never want to directly look
                    // at the ProjectReference items in the project, as those don't always create project references
                    // if things like OutputItemType or ReferenceOutputAssembly are set. It's also possible that other
                    // MSBuild logic is adding or removing properties too.
                    if (StringComparer.OrdinalIgnoreCase.Equals(referenceSourceTarget, ItemNames.ProjectReference))
                    {
                        var projectReferenceOriginalItemSpec = referencePathItem.GetMetadataValue(MetadataNames.ProjectReferenceOriginalItemSpec);
                        if (projectReferenceOriginalItemSpec.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
                        {
                            var projectReferenceFilePath = Path.GetFullPath(Path.Combine(projectFolderPath, projectReferenceOriginalItemSpec));

                            projectReferences.Add(projectReferenceFilePath);

                            if (!string.IsNullOrEmpty(aliases))
                            {
                                projectReferenceAliases[projectReferenceFilePath] = aliases;
                            }

                            continue;
                        }
                    }

                    var fullPath = referencePathItem.GetMetadataValue(MetadataNames.FullPath);
                    if (!string.IsNullOrEmpty(fullPath))
                    {
                        references.Add(fullPath);

                        if (!string.IsNullOrEmpty(aliases))
                        {
                            referenceAliases[fullPath] = aliases;
                        }
                    }
                }

                var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
                var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));
                var additionalFiles   = GetFullPaths(projectInstance.GetItems(ItemNames.AdditionalFiles));
                var editorConfigFiles = GetFullPaths(projectInstance.GetItems(ItemNames.EditorConfigFiles));
                var includeGlobs      = project.GetAllGlobs().Select(x => x.MsBuildGlob).ToImmutableArray();

                return(new ProjectData(
                           guid,
                           name,
                           assemblyName,
                           targetPath,
                           outputPath,
                           intermediateOutputPath,
                           projectAssetsFile,
                           configuration,
                           platform,
                           targetFramework,
                           targetFrameworks,
                           outputKind,
                           languageVersion,
                           nullableContextOptions,
                           allowUnsafeCode,
                           checkForOverflowUnderflow,
                           documentationFile,
                           preprocessorSymbolNames,
                           suppressedDiagnosticIds,
                           warningsAsErrors,
                           warningsNotAsErrors,
                           signAssembly,
                           assemblyOriginatorKeyFile,
                           sourceFiles,
                           projectReferences.ToImmutable(),
                           references.ToImmutable(),
                           packageReferences,
                           analyzers,
                           additionalFiles,
                           editorConfigFiles,
                           treatWarningsAsErrors,
                           defaultNamespace,
                           runAnalyzers,
                           runAnalyzersDuringLiveAnalysis,
                           ruleset,
                           referenceAliases.ToImmutableDictionary(),
                           projectReferenceAliases.ToImmutable(),
                           includeGlobs));
            }
Example #19
0
 protected CommandLineArgumentReader(MSB.Execution.ProjectInstance project)
 {
     Project  = project;
     _builder = ImmutableArray.CreateBuilder <string>();
 }
 public static ImmutableArray <string> Read(MSB.Execution.ProjectInstance project)
 {
     return(new VisualBasicCommandLineArgumentReader(project).Read());
 }
 public VisualBasicCommandLineArgumentReader(MSB.Execution.ProjectInstance project)
     : base(project)
 {
 }
Example #22
0
            private void InitializeFromModel(VisualBasicProjectFileLoader.VisualBasicProjectFile.VisualBasicCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject)
            {
                compilerInputs.BeginInitialization();
                compilerInputs.SetBaseAddress(base.ReadPropertyString(executedProject, "OutputType"), base.ReadPropertyString(executedProject, "BaseAddress"));
                compilerInputs.SetCodePage(base.ReadPropertyInt(executedProject, "CodePage"));
                compilerInputs.SetDebugType(base.ReadPropertyBool(executedProject, "DebugSymbols"), base.ReadPropertyString(executedProject, "DebugType"));
                compilerInputs.SetDefineConstants(base.ReadPropertyString(executedProject, "FinalDefineConstants", "DefineConstants"));
                compilerInputs.SetFeatures(base.ReadPropertyString(executedProject, "Features"));
                compilerInputs.SetDelaySign(base.ReadPropertyBool(executedProject, "DelaySign"));
                compilerInputs.SetDisabledWarnings(base.ReadPropertyString(executedProject, "NoWarn"));
                compilerInputs.SetDocumentationFile(base.GetItemString(executedProject, "DocFileItem"));
                compilerInputs.SetErrorReport(base.ReadPropertyString(executedProject, "ErrorReport"));
                compilerInputs.SetFileAlignment(base.ReadPropertyInt(executedProject, "FileAlignment"));
                compilerInputs.SetGenerateDocumentation(base.ReadPropertyBool(executedProject, "GenerateDocumentation"));
                compilerInputs.SetHighEntropyVA(base.ReadPropertyBool(executedProject, "HighEntropyVA"));
                compilerInputs.SetFeatures(base.ReadPropertyString(executedProject, "Features"));

                var _imports = this.GetTaskItems(executedProject, "Import");

                if (_imports != null)
                {
                    compilerInputs.SetImports(_imports.ToArray());
                }

                var signAssembly = ReadPropertyBool(executedProject, "SignAssembly");

                if (signAssembly)
                {
                    var keyFile = ReadPropertyString(executedProject, "KeyOriginatorFile", "AssemblyOriginatorKeyFile");
                    if (!string.IsNullOrEmpty(keyFile))
                    {
                        compilerInputs.SetKeyFile(keyFile);
                    }

                    var keyContainer = ReadPropertyString(executedProject, "KeyContainerName");
                    if (!string.IsNullOrEmpty(keyContainer))
                    {
                        compilerInputs.SetKeyContainer(keyContainer);
                    }
                }

                compilerInputs.SetLanguageVersion(base.ReadPropertyString(executedProject, "LangVersion"));
                compilerInputs.SetMainEntryPoint(base.ReadPropertyString(executedProject, "StartupObject"));
                compilerInputs.SetModuleAssemblyName(base.ReadPropertyString(executedProject, "ModuleEntryPoint"));
                compilerInputs.SetNoStandardLib(base.ReadPropertyBool(executedProject, "NoCompilerStandardLib", "NoStdLib"));
                compilerInputs.SetNoWarnings(base.ReadPropertyBool(executedProject, "_NoWarnings"));
                compilerInputs.SetOptimize(base.ReadPropertyBool(executedProject, "Optimize"));
                compilerInputs.SetOptionCompare(base.ReadPropertyString(executedProject, "OptionCompare"));
                compilerInputs.SetOptionExplicit(base.ReadPropertyBool(executedProject, "OptionExplicit"));
                compilerInputs.SetOptionInfer(base.ReadPropertyBool(executedProject, "OptionInfer"));
                compilerInputs.SetOptionStrictType(base.ReadPropertyString(executedProject, "OptionStrict"));
                compilerInputs.SetOutputAssembly(base.GetItemString(executedProject, "IntermediateAssembly"));

                if (base.ReadPropertyBool(executedProject, "Prefer32Bit"))
                {
                    compilerInputs.SetPlatformWith32BitPreference(base.ReadPropertyString(executedProject, "PlatformTarget"));
                }
                else
                {
                    compilerInputs.SetPlatform(base.ReadPropertyString(executedProject, "PlatformTarget"));
                }

                compilerInputs.SetRemoveIntegerChecks(base.ReadPropertyBool(executedProject, "RemoveIntegerChecks"));
                compilerInputs.SetRootNamespace(base.ReadPropertyString(executedProject, "RootNamespace"));
                compilerInputs.SetSdkPath(base.ReadPropertyString(executedProject, "FrameworkPathOverride"));
                compilerInputs.SetSubsystemVersion(base.ReadPropertyString(executedProject, "SubsystemVersion"));
                compilerInputs.SetTargetCompactFramework(base.ReadPropertyBool(executedProject, "TargetCompactFramework"));
                compilerInputs.SetTargetType(base.ReadPropertyString(executedProject, "OutputType"));

                // Decode the warning options from RuleSet file prior to reading explicit settings in the project file, so that project file settings prevail for duplicates.
                compilerInputs.SetRuleSet(base.ReadPropertyString(executedProject, "RuleSet"));

                compilerInputs.SetTreatWarningsAsErrors(base.ReadPropertyBool(executedProject, "SetTreatWarningsAsErrors"));
                compilerInputs.SetVBRuntime(base.ReadPropertyString(executedProject, "VbRuntime"));
                compilerInputs.SetWarningsAsErrors(base.ReadPropertyString(executedProject, "WarningsAsErrors"));
                compilerInputs.SetWarningsNotAsErrors(base.ReadPropertyString(executedProject, "WarningsNotAsErrors"));
                compilerInputs.SetReferences(this.GetMetadataReferencesFromModel(executedProject).ToArray());
                compilerInputs.SetAnalyzers(this.GetAnalyzerReferencesFromModel(executedProject).ToArray());
                compilerInputs.SetAdditionalFiles(this.GetAdditionalFilesFromModel(executedProject).ToArray());
                compilerInputs.SetSources(this.GetDocumentsFromModel(executedProject).ToArray());
                compilerInputs.EndInitialization();
            }
Example #23
0
 protected abstract ImmutableArray <string> ReadCommandLineArgs(
     MSB.Execution.ProjectInstance project
     );
Example #24
0
 public static IEnumerable <MSB.Framework.ITaskItem> GetAnalyzers(
     this MSB.Execution.ProjectInstance executedProject
     ) => executedProject.GetItems(ItemNames.Analyzer);
Example #25
0
 private CSharpCommandLineArgumentReader(MSB.Execution.ProjectInstance project)
     : base(project)
 {
 }
Example #26
0
            private IEnumerable <DocumentFileInfo> GetDocuments(IEnumerable <MSB.Framework.ITaskItem> sources, MSB.Execution.ProjectInstance executedProject)
            {
                IEnumerable <DocumentFileInfo> result;

                if (sources == null)
                {
                    result = ImmutableArray <DocumentFileInfo> .Empty;
                }

                var projectDirectory = executedProject.Directory;

                if (!projectDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    projectDirectory += Path.DirectorySeparatorChar;
                }

                return(sources
                       .Where(s => !System.IO.Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal))
                       .Select(s => new DocumentFileInfo(GetDocumentFilePath(s), GetDocumentLogicalPath(s, projectDirectory), IsDocumentLinked(s), IsDocumentGenerated(s))).ToImmutableArray());
            }
Example #27
0
 protected abstract IEnumerable <MSB.Framework.ITaskItem> GetCompilerCommandLineArgs(
     MSB.Execution.ProjectInstance executedProject
     );
Example #28
0
 public static IEnumerable <MSB.Framework.ITaskItem> GetEditorConfigFiles(
     this MSB.Execution.ProjectInstance executedProject
     ) => executedProject.GetItems(ItemNames.EditorConfigFiles);
Example #29
0
            public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
            {
                var guid                   = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
                var name                   = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName           = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath             = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath             = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
                var intermediateOutputPath = projectInstance.GetPropertyValue(PropertyNames.IntermediateOutputPath);
                var projectAssetsFile      = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);
                var configuration          = projectInstance.GetPropertyValue(PropertyNames.Configuration);
                var platform               = projectInstance.GetPropertyValue(PropertyNames.Platform);

                var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = projectInstance.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var outputKind                = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
                var documentationFile         = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames   = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds   = PropertyConverter.ToSuppressedDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
                var signAssembly              = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var assemblyOriginatorKeyFile = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

                var sourceFiles = GetFullPaths(
                    projectInstance.GetItems(ItemNames.Compile), filter: FileNameIsNotGenerated);

                var projectReferences = GetFullPaths(
                    projectInstance.GetItems(ItemNames.ProjectReference), filter: IsCSharpProject);

                var references = ImmutableArray.CreateBuilder <string>();

                foreach (var referencePathItem in projectInstance.GetItems(ItemNames.ReferencePath))
                {
                    var referenceSourceTarget = referencePathItem.GetMetadataValue(MetadataNames.ReferenceSourceTarget);

                    if (StringComparer.OrdinalIgnoreCase.Equals(referenceSourceTarget, ItemNames.ProjectReference))
                    {
                        // If the reference was sourced from a project reference, we have two choices:
                        //
                        //   1. If the reference is a C# project reference, we shouldn't add it because it'll just duplicate
                        //      the project reference.
                        //   2. If the reference is *not* a C# project reference, we should keep this reference because the
                        //      project reference was already removed.

                        var originalItemSpec = referencePathItem.GetMetadataValue(MetadataNames.OriginalItemSpec);
                        if (originalItemSpec.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                    }

                    var fullPath = referencePathItem.GetMetadataValue(MetadataNames.FullPath);
                    if (!string.IsNullOrEmpty(fullPath))
                    {
                        references.Add(fullPath);
                    }
                }

                var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
                var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));

                return(new ProjectData(guid, name,
                                       assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile,
                                       configuration, platform, targetFramework, targetFrameworks,
                                       outputKind, languageVersion, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds,
                                       signAssembly, assemblyOriginatorKeyFile,
                                       sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers));
            }
Example #30
0
 public static IEnumerable <MSB.Framework.ITaskItem> GetMetadataReferences(
     this MSB.Execution.ProjectInstance executedProject
     ) => executedProject.GetItems(ItemNames.ReferencePath);