private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { string projectDirectory = executedProject.Directory; if (!projectDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) { projectDirectory += Path.DirectorySeparatorChar; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_")) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableList(); var metadataRefs = compilerInputs.References.SelectMany(r => MakeMetadataInfo(r)); var analyzerRefs = compilerInputs.AnalyzerReferences.Select(r => new AnalyzerFileReference(GetDocumentFilePath(r))); if (!compilerInputs.NoStandardLib) { var mscorlibPath = typeof(object).Assembly.Location; metadataRefs = metadataRefs.Concat(new[] { new MetadataInfo(mscorlibPath) }); } return new ProjectFileInfo( this.Guid, this.GetTargetPath(), this.GetAssemblyName(), compilerInputs.CompilationOptions, compilerInputs.ParseOptions, docs, this.GetProjectReferences(executedProject), metadataRefs, analyzerRefs, appConfigPath: compilerInputs.AppConfigPath); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { string projectDirectory = executedProject.Directory; string directorySeparator = Path.DirectorySeparatorChar.ToString(); if (!projectDirectory.EndsWith(directorySeparator, StringComparison.OrdinalIgnoreCase)) { projectDirectory += directorySeparator; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal)) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var additionalDocs = compilerInputs.AdditionalSources .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName); var assemblyName = this.GetAssemblyName(); return(new ProjectFileInfo( outputPath, assemblyName, compilerInputs.CommandLineArgs, docs, additionalDocs, this.GetProjectReferences(executedProject))); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { string projectDirectory = executedProject.Directory; string directorySeparator = Path.DirectorySeparatorChar.ToString(); if (!projectDirectory.EndsWith(directorySeparator, StringComparison.OrdinalIgnoreCase)) { projectDirectory += directorySeparator; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal)) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var additionalDocs = compilerInputs.AdditionalSources .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName); var assemblyName = this.GetAssemblyName(); return new ProjectFileInfo( outputPath, assemblyName, compilerInputs.CommandLineArgs, docs, additionalDocs, this.GetProjectReferences(executedProject)); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { string projectDirectory = executedProject.Directory; if (!projectDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) { projectDirectory += Path.DirectorySeparatorChar; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_")) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); IEnumerable<MetadataReference> metadataRefs; IEnumerable<AnalyzerReference> analyzerRefs; this.GetReferences(compilerInputs, executedProject, out metadataRefs, out analyzerRefs); var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName); var assemblyName = this.GetAssemblyName(); return new ProjectFileInfo( this.Guid, outputPath, assemblyName, compilerInputs.CompilationOptions, compilerInputs.ParseOptions, docs, this.GetProjectReferences(executedProject), metadataRefs, analyzerRefs); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { string projectDirectory = executedProject.Directory; if (!projectDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) { projectDirectory += Path.DirectorySeparatorChar; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_")) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableList(); var metadataRefs = compilerInputs.References.SelectMany(r => MakeMetadataInfo(r)); if (!compilerInputs.NoStandardLib) { var mscorlibPath = typeof(object).Assembly.Location; metadataRefs = metadataRefs.Concat(new[] { new MetadataInfo(mscorlibPath) }); } return(new ProjectFileInfo( this.Guid, this.GetTargetPath(), this.GetAssemblyName(), compilerInputs.CompilationOptions, compilerInputs.ParseOptions, docs, this.GetProjectReferences(executedProject), metadataRefs, compilerInputs.AppConfigPath)); }
private void GetReferences( CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject, out IEnumerable <MetadataReference> metadataReferences, out IEnumerable <AnalyzerReference> analyzerReferences) { // use command line parser to do reference translation same as command line compiler var args = new List <string>(); if (compilerInputs.LibPaths != null && compilerInputs.LibPaths.Count > 0) { args.Add("/lib:\"" + string.Join(";", compilerInputs.LibPaths) + "\""); } foreach (var mr in compilerInputs.References) { var filePath = GetDocumentFilePath(mr); var aliases = GetAliases(mr); if (aliases.IsDefaultOrEmpty) { args.Add("/r:\"" + filePath + "\""); } else { foreach (var alias in aliases) { args.Add("/r:" + alias + "=\"" + filePath + "\""); } } } foreach (var ar in compilerInputs.AnalyzerReferences) { var filePath = GetDocumentFilePath(ar); args.Add("/a:\"" + filePath + "\""); } if (compilerInputs.NoStandardLib) { args.Add("/nostdlib"); } var commandLineParser = CSharpCommandLineParser.Default; var commandLineArgs = commandLineParser.Parse(args, executedProject.Directory, RuntimeEnvironment.GetRuntimeDirectory()); var resolver = new MetadataFileReferenceResolver(commandLineArgs.ReferencePaths, commandLineArgs.BaseDirectory); metadataReferences = commandLineArgs.ResolveMetadataReferences(new AssemblyReferenceResolver(resolver, _metadataService.GetProvider())); var analyzerLoader = _analyzerService.GetLoader(); foreach (var path in commandLineArgs.AnalyzerReferences.Select(r => r.FilePath)) { analyzerLoader.AddDependencyLocation(path); } analyzerReferences = commandLineArgs.ResolveAnalyzerReferences(analyzerLoader); }
public override async Task <ProjectFileInfo> GetProjectFileInfoAsync(CancellationToken cancellationToken) { var compilerInputs = new CSharpCompilerInputs(this); var executedProject = await this.BuildAsync("Csc", compilerInputs, cancellationToken).ConfigureAwait(false); if (!compilerInputs.Initialized) { // if msbuild didn't reach the CSC task for some reason, attempt to initialize using the variables that were defined so far. this.InitializeFromModel(compilerInputs, executedProject); } return(CreateProjectFileInfo(compilerInputs, executedProject)); }
public override async Task<ProjectFileInfo> GetProjectFileInfoAsync(CancellationToken cancellationToken) { var compilerInputs = new CSharpCompilerInputs(this); var executedProject = await this.BuildAsync("Csc", compilerInputs, cancellationToken).ConfigureAwait(false); if (!compilerInputs.Initialized) { // if msbuild didn't reach the CSC task for some reason, attempt to initialize using the variables that were defined so far. this.InitializeFromModel(compilerInputs, executedProject); } return CreateProjectFileInfo(compilerInputs, executedProject); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, BuildInfo buildInfo) { var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName); var assemblyName = this.GetAssemblyName(); var project = buildInfo.Project; if (project == null) { return(new ProjectFileInfo( outputPath, assemblyName, commandLineArgs: SpecializedCollections.EmptyEnumerable <string>(), documents: SpecializedCollections.EmptyEnumerable <DocumentFileInfo>(), additionalDocuments: SpecializedCollections.EmptyEnumerable <DocumentFileInfo>(), projectReferences: SpecializedCollections.EmptyEnumerable <ProjectFileReference>(), errorMessage: buildInfo.ErrorMessage)); } string projectDirectory = project.Directory; string directorySeparator = Path.DirectorySeparatorChar.ToString(); if (!projectDirectory.EndsWith(directorySeparator, StringComparison.OrdinalIgnoreCase)) { projectDirectory += directorySeparator; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal)) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var additionalDocs = compilerInputs.AdditionalSources .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); return(new ProjectFileInfo( outputPath, assemblyName, compilerInputs.CommandLineArgs, docs, additionalDocs, this.GetProjectReferences(buildInfo.Project), buildInfo.ErrorMessage)); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, BuildInfo buildInfo) { var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName); var assemblyName = this.GetAssemblyName(); var project = buildInfo.Project; if (project == null) { return new ProjectFileInfo( outputPath, assemblyName, commandLineArgs: SpecializedCollections.EmptyEnumerable<string>(), documents: SpecializedCollections.EmptyEnumerable<DocumentFileInfo>(), additionalDocuments: SpecializedCollections.EmptyEnumerable<DocumentFileInfo>(), projectReferences: SpecializedCollections.EmptyEnumerable<ProjectFileReference>(), errorMessage: buildInfo.ErrorMessage); } string projectDirectory = project.Directory; string directorySeparator = Path.DirectorySeparatorChar.ToString(); if (!projectDirectory.EndsWith(directorySeparator, StringComparison.OrdinalIgnoreCase)) { projectDirectory += directorySeparator; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal)) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var additionalDocs = compilerInputs.AdditionalSources .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); return new ProjectFileInfo( outputPath, assemblyName, compilerInputs.CommandLineArgs, docs, additionalDocs, this.GetProjectReferences(buildInfo.Project), buildInfo.ErrorMessage); }
private ProjectFileInfo CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { string projectDirectory = executedProject.Directory; string directorySeparator = Path.DirectorySeparatorChar.ToString(); if (!projectDirectory.EndsWith(directorySeparator, StringComparison.OrdinalIgnoreCase)) { projectDirectory += directorySeparator; } var docs = compilerInputs.Sources .Where(s => !Path.GetFileName(s.ItemSpec).StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal)) .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); var additionalDocs = compilerInputs.AdditionalFiles .Select(s => MakeDocumentFileInfo(projectDirectory, s)) .ToImmutableArray(); IEnumerable <MetadataReference> metadataRefs; IEnumerable <AnalyzerReference> analyzerRefs; this.GetReferences(compilerInputs, executedProject, out metadataRefs, out analyzerRefs); var outputPath = Path.Combine(this.GetOutputDirectory(), compilerInputs.OutputFileName); var assemblyName = this.GetAssemblyName(); var msbuildData = _msbuildHost.Create(compilerInputs.Options); return(new ProjectFileInfo( outputPath, assemblyName, msbuildData.CompilationOptions, msbuildData.ParseOptions, compilerInputs.CodePage, docs, additionalDocs, this.GetProjectReferences(executedProject), metadataRefs, analyzerRefs)); }
private void InitializeFromModel(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { compilerInputs.BeginInitialization(); compilerInputs.SetAllowUnsafeBlocks(this.ReadPropertyBool(executedProject, "AllowUnsafeBlocks")); compilerInputs.SetApplicationConfiguration(this.ReadPropertyString(executedProject, "AppConfigForCompiler")); compilerInputs.SetBaseAddress(this.ReadPropertyString(executedProject, "BaseAddress")); compilerInputs.SetCheckForOverflowUnderflow(this.ReadPropertyBool(executedProject, "CheckForOverflowUnderflow")); compilerInputs.SetCodePage(this.ReadPropertyInt(executedProject, "CodePage")); compilerInputs.SetDebugType(this.ReadPropertyString(executedProject, "DebugType")); compilerInputs.SetDefineConstants(this.ReadPropertyString(executedProject, "DefineConstants")); compilerInputs.SetFeatures(this.ReadPropertyString(executedProject, "Features")); var delaySignProperty = this.GetProperty("DelaySign"); compilerInputs.SetDelaySign(delaySignProperty != null && !string.IsNullOrEmpty(delaySignProperty.EvaluatedValue), this.ReadPropertyBool(executedProject, "DelaySign")); compilerInputs.SetDisabledWarnings(this.ReadPropertyString(executedProject, "NoWarn")); compilerInputs.SetDocumentationFile(this.GetItemString(executedProject, "DocFileItem")); compilerInputs.SetEmitDebugInformation(this.ReadPropertyBool(executedProject, "DebugSymbols")); compilerInputs.SetErrorReport(this.ReadPropertyString(executedProject, "ErrorReport")); compilerInputs.SetFileAlignment(this.ReadPropertyInt(executedProject, "FileAlignment")); compilerInputs.SetGenerateFullPaths(this.ReadPropertyBool(executedProject, "GenerateFullPaths")); compilerInputs.SetHighEntropyVA(this.ReadPropertyBool(executedProject, "HighEntropyVA")); bool signAssembly = this.ReadPropertyBool(executedProject, "SignAssembly"); if (signAssembly) { compilerInputs.SetKeyContainer(this.ReadPropertyString(executedProject, "KeyContainerName")); compilerInputs.SetKeyFile(this.ReadPropertyString(executedProject, "KeyOriginatorFile", "AssemblyOriginatorKeyFile")); } compilerInputs.SetLangVersion(this.ReadPropertyString(executedProject, "LangVersion")); compilerInputs.SetMainEntryPoint(null, this.ReadPropertyString(executedProject, "StartupObject")); compilerInputs.SetModuleAssemblyName(this.ReadPropertyString(executedProject, "ModuleAssemblyName")); compilerInputs.SetNoStandardLib(this.ReadPropertyBool(executedProject, "NoCompilerStandardLib")); compilerInputs.SetOptimize(this.ReadPropertyBool(executedProject, "Optimize")); compilerInputs.SetOutputAssembly(this.GetItemString(executedProject, "IntermediateAssembly")); compilerInputs.SetPdbFile(this.ReadPropertyString(executedProject, "PdbFile")); if (this.ReadPropertyBool(executedProject, "Prefer32Bit")) { compilerInputs.SetPlatformWith32BitPreference(this.ReadPropertyString(executedProject, "PlatformTarget")); } else { compilerInputs.SetPlatform(this.ReadPropertyString(executedProject, "PlatformTarget")); } compilerInputs.SetSubsystemVersion(this.ReadPropertyString(executedProject, "SubsystemVersion")); compilerInputs.SetTargetType(this.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(this.ReadPropertyString(executedProject, "RuleSet")); compilerInputs.SetTreatWarningsAsErrors(this.ReadPropertyBool(executedProject, "TreatWarningsAsErrors")); compilerInputs.SetWarningLevel(this.ReadPropertyInt(executedProject, "WarningLevel")); compilerInputs.SetWarningsAsErrors(this.ReadPropertyString(executedProject, "WarningsAsErrors")); compilerInputs.SetWarningsNotAsErrors(this.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()); string errorMessage; int errorCode; compilerInputs.EndInitialization(out errorMessage, out errorCode); }
private void InitializeFromModel(CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject) { compilerInputs.BeginInitialization(); compilerInputs.SetAllowUnsafeBlocks(this.ReadPropertyBool(executedProject, "AllowUnsafeBlocks")); compilerInputs.SetApplicationConfiguration(this.ReadPropertyString(executedProject, "AppConfigForCompiler")); compilerInputs.SetBaseAddress(this.ReadPropertyString(executedProject, "BaseAddress")); compilerInputs.SetCheckForOverflowUnderflow(this.ReadPropertyBool(executedProject, "CheckForOverflowUnderflow")); compilerInputs.SetCodePage(this.ReadPropertyInt(executedProject, "CodePage")); compilerInputs.SetDebugType(this.ReadPropertyString(executedProject, "DebugType")); compilerInputs.SetDefineConstants(this.ReadPropertyString(executedProject, "DefineConstants")); var delaySignProperty = this.GetProperty("DelaySign"); compilerInputs.SetDelaySign(delaySignProperty != null && !string.IsNullOrEmpty(delaySignProperty.EvaluatedValue), this.ReadPropertyBool(executedProject, "DelaySign")); compilerInputs.SetDisabledWarnings(this.ReadPropertyString(executedProject, "NoWarn")); compilerInputs.SetDocumentationFile(this.GetItemString(executedProject, "DocFileItem")); compilerInputs.SetEmitDebugInformation(this.ReadPropertyBool(executedProject, "DebugSymbols")); compilerInputs.SetErrorReport(this.ReadPropertyString(executedProject, "ErrorReport")); compilerInputs.SetFileAlignment(this.ReadPropertyInt(executedProject, "FileAlignment")); compilerInputs.SetGenerateFullPaths(this.ReadPropertyBool(executedProject, "GenerateFullPaths")); compilerInputs.SetHighEntropyVA(this.ReadPropertyBool(executedProject, "HighEntropyVA")); bool signAssembly = this.ReadPropertyBool(executedProject, "SignAssembly"); if (signAssembly) { compilerInputs.SetKeyContainer(this.ReadPropertyString(executedProject, "KeyContainerName")); compilerInputs.SetKeyFile(this.ReadPropertyString(executedProject, "KeyOriginatorFile", "AssemblyOriginatorKeyFile")); } compilerInputs.SetLangVersion(this.ReadPropertyString(executedProject, "LangVersion")); compilerInputs.SetMainEntryPoint(null, this.ReadPropertyString(executedProject, "StartupObject")); compilerInputs.SetModuleAssemblyName(this.ReadPropertyString(executedProject, "ModuleAssemblyName")); compilerInputs.SetNoStandardLib(this.ReadPropertyBool(executedProject, "NoCompilerStandardLib")); compilerInputs.SetOptimize(this.ReadPropertyBool(executedProject, "Optimize")); compilerInputs.SetOutputAssembly(this.GetItemString(executedProject, "IntermediateAssembly")); compilerInputs.SetPdbFile(this.ReadPropertyString(executedProject, "PdbFile")); if (this.ReadPropertyBool(executedProject, "Prefer32Bit")) { compilerInputs.SetPlatformWith32BitPreference(this.ReadPropertyString(executedProject, "PlatformTarget")); } else { compilerInputs.SetPlatform(this.ReadPropertyString(executedProject, "PlatformTarget")); } compilerInputs.SetSubsystemVersion(this.ReadPropertyString(executedProject, "SubsystemVersion")); compilerInputs.SetTargetType(this.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(this.ReadPropertyString(executedProject, "RuleSet")); compilerInputs.SetTreatWarningsAsErrors(this.ReadPropertyBool(executedProject, "TreatWarningsAsErrors")); compilerInputs.SetWarningLevel(this.ReadPropertyInt(executedProject, "WarningLevel")); compilerInputs.SetWarningsAsErrors(this.ReadPropertyString(executedProject, "WarningsAsErrors")); compilerInputs.SetWarningsNotAsErrors(this.ReadPropertyString(executedProject, "WarningsNotAsErrors")); compilerInputs.SetReferences(this.GetMetadataReferencesFromModel(executedProject).ToArray()); compilerInputs.SetAnalyzers(this.GetAnalyzerReferencesFromModel(executedProject).ToArray()); compilerInputs.SetSources(this.GetDocumentsFromModel(executedProject).ToArray()); string errorMessage; int errorCode; compilerInputs.EndInitialization(out errorMessage, out errorCode); }
private void GetReferences( CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject, out IEnumerable<MetadataReference> metadataReferences, out IEnumerable<AnalyzerReference> analyzerReferences) { // use command line parser to do reference translation same as command line compiler var args = new List<string>(); if (compilerInputs.LibPaths != null && compilerInputs.LibPaths.Count > 0) { args.Add("/lib:\"" + string.Join(";", compilerInputs.LibPaths) + "\""); } foreach (var mr in compilerInputs.References) { if (!IsProjectReferenceOutputAssembly(mr)) { var filePath = GetDocumentFilePath(mr); var aliases = GetAliases(mr); if (aliases.IsDefaultOrEmpty) { args.Add("/r:\"" + filePath + "\""); } else { foreach (var alias in aliases) { args.Add("/r:" + alias + "=\"" + filePath + "\""); } } } } foreach (var ar in compilerInputs.AnalyzerReferences) { var filePath = GetDocumentFilePath(ar); args.Add("/a:\"" + filePath + "\""); } if (compilerInputs.NoStandardLib) { args.Add("/nostdlib"); } var commandLineArgs = _commandLineArgumentsFactoryService.CreateCommandLineArguments(args, executedProject.Directory, isInteractive: false, sdkDirectory: RuntimeEnvironment.GetRuntimeDirectory()); var resolver = new MetadataFileReferenceResolver(commandLineArgs.ReferencePaths, commandLineArgs.BaseDirectory); metadataReferences = commandLineArgs.ResolveMetadataReferences(new AssemblyReferenceResolver(resolver, _metadataService.GetProvider())); var analyzerLoader = _analyzerService.GetLoader(); foreach (var path in commandLineArgs.AnalyzerReferences.Select(r => r.FilePath)) { analyzerLoader.AddDependencyLocation(path); } analyzerReferences = commandLineArgs.ResolveAnalyzerReferences(analyzerLoader); }
private void GetReferences( CSharpCompilerInputs compilerInputs, MSB.Execution.ProjectInstance executedProject, out IEnumerable<MetadataReference> metadataReferences, out IEnumerable<AnalyzerReference> analyzerReferences) { // use command line parser to do reference translation same as command line compiler var args = new List<string>(); if (compilerInputs.LibPaths != null && compilerInputs.LibPaths.Count > 0) { args.Add("/lib:\"" + string.Join(";", compilerInputs.LibPaths) + "\""); } foreach (var mr in compilerInputs.References) { var filePath = GetDocumentFilePath(mr); var aliases = GetAliases(mr); if (aliases.IsDefaultOrEmpty) { args.Add("/r:\"" + filePath + "\""); } else { foreach (var alias in aliases) { args.Add("/r:" + alias + "=\"" + filePath + "\""); } } } foreach (var ar in compilerInputs.AnalyzerReferences) { var filePath = GetDocumentFilePath(ar); args.Add("/a:\"" + filePath + "\""); } if (compilerInputs.NoStandardLib) { args.Add("/nostdlib"); } var commandLineParser = CSharpCommandLineParser.Default; var commandLineArgs = commandLineParser.Parse(args, executedProject.Directory); var resolver = new MetadataFileReferenceResolver(commandLineArgs.ReferencePaths, commandLineArgs.BaseDirectory); metadataReferences = commandLineArgs.ResolveMetadataReferences(new AssemblyReferenceResolver(resolver, _metadataService.GetProvider())); analyzerReferences = commandLineArgs.ResolveAnalyzerReferences(); }