public AbstractLegacyProject( string projectSystemName, IVsHierarchy hierarchy, string language, IServiceProvider serviceProvider, IThreadingContext threadingContext, string externalErrorReportingPrefix, HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt, ICommandLineParserService commandLineParserServiceOpt) : base(threadingContext) { Contract.ThrowIfNull(hierarchy); var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); Workspace = componentModel.GetService <VisualStudioWorkspace>(); var projectFilePath = hierarchy.GetProjectFilePath(); if (projectFilePath != null && !File.Exists(projectFilePath)) { projectFilePath = null; } var projectFactory = componentModel.GetService <VisualStudioProjectFactory>(); VisualStudioProject = projectFactory.CreateAndAddToWorkspace( projectSystemName, language, new VisualStudioProjectCreationInfo { // The workspace requires an assembly name so we can make compilations. We'll use // projectSystemName because they'll have a better one eventually. AssemblyName = projectSystemName, FilePath = projectFilePath, Hierarchy = hierarchy, ProjectGuid = GetProjectIDGuid(hierarchy), DefaultNamespace = GetDefaultNamespace(hierarchy, language) }); Hierarchy = hierarchy; ConnectHierarchyEvents(); RefreshBinOutputPath(); // TODO: remove this terrible hack, which is working around shims throwing in not-good ways try { _externalErrorReporter = new ProjectExternalErrorReporter(VisualStudioProject.Id, externalErrorReportingPrefix, serviceProvider); _editAndContinueProject = new VsENCRebuildableProjectImpl(Workspace, VisualStudioProject, serviceProvider); } catch (Exception) { } _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>(); _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy); }
public AbstractLegacyProject( string projectSystemName, IVsHierarchy hierarchy, string language, bool isVsIntellisenseProject, IServiceProvider serviceProvider, IThreadingContext threadingContext, string externalErrorReportingPrefix ) : base(threadingContext, assertIsForeground: true) { Contract.ThrowIfNull(hierarchy); var componentModel = (IComponentModel)serviceProvider.GetService( typeof(SComponentModel) ); Workspace = componentModel.GetService <VisualStudioWorkspace>(); var workspaceImpl = (VisualStudioWorkspaceImpl)Workspace; var projectFilePath = hierarchy.TryGetProjectFilePath(); if (projectFilePath != null && !File.Exists(projectFilePath)) { projectFilePath = null; } if (projectFilePath != null) { _projectDirectory = Path.GetDirectoryName(projectFilePath); } if (isVsIntellisenseProject) { // IVsIntellisenseProjects are usually used for contained language cases, which means these projects don't have any real // output path that we should consider. Since those point to the same IVsHierarchy as another project, we end up with two projects // with the same output path, which potentially breaks conversion of metadata references to project references. However they're // also used for database projects and a few other cases where there there isn't a "primary" IVsHierarchy. // As a heuristic here we'll ignore the output path if we already have another project tied to the IVsHierarchy. foreach (var projectId in Workspace.CurrentSolution.ProjectIds) { if (Workspace.GetHierarchy(projectId) == hierarchy) { _ignoreOutputPath = true; break; } } } var projectFactory = componentModel.GetService <VisualStudioProjectFactory>(); VisualStudioProject = threadingContext.JoinableTaskFactory.Run( () => projectFactory.CreateAndAddToWorkspaceAsync( projectSystemName, language, new VisualStudioProjectCreationInfo { // The workspace requires an assembly name so we can make compilations. We'll use // projectSystemName because they'll have a better one eventually. AssemblyName = projectSystemName, FilePath = projectFilePath, Hierarchy = hierarchy, ProjectGuid = GetProjectIDGuid(hierarchy), }, CancellationToken.None ) ); workspaceImpl.AddProjectRuleSetFileToInternalMaps( VisualStudioProject, () => VisualStudioProjectOptionsProcessor.EffectiveRuleSetFilePath ); // 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) VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy); if ( TryGetPropertyValue( hierarchy, AdditionalPropertyNames.MaxSupportedLangVersion, out var maxLangVer ) ) { VisualStudioProject.MaxLangVersion = maxLangVer; } if ( TryGetBoolPropertyValue( hierarchy, AdditionalPropertyNames.RunAnalyzers, out var runAnayzers ) ) { VisualStudioProject.RunAnalyzers = runAnayzers; } if ( TryGetBoolPropertyValue( hierarchy, AdditionalPropertyNames.RunAnalyzersDuringLiveAnalysis, out var runAnayzersDuringLiveAnalysis ) ) { VisualStudioProject.RunAnalyzersDuringLiveAnalysis = runAnayzersDuringLiveAnalysis; } Hierarchy = hierarchy; ConnectHierarchyEvents(); RefreshBinOutputPath(); workspaceImpl.SubscribeExternalErrorDiagnosticUpdateSourceToSolutionBuildEvents(); _externalErrorReporter = new ProjectExternalErrorReporter( VisualStudioProject.Id, externalErrorReportingPrefix, language, workspaceImpl ); _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>(); _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy); }
public AbstractLegacyProject( string projectSystemName, IVsHierarchy hierarchy, string language, IServiceProvider serviceProvider, IThreadingContext threadingContext, string externalErrorReportingPrefix, HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt, ICommandLineParserService commandLineParserServiceOpt) : base(threadingContext) { Contract.ThrowIfNull(hierarchy); var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); Workspace = componentModel.GetService <VisualStudioWorkspace>(); var projectFilePath = hierarchy.TryGetProjectFilePath(); if (projectFilePath != null && !File.Exists(projectFilePath)) { projectFilePath = null; } var projectFactory = componentModel.GetService <VisualStudioProjectFactory>(); VisualStudioProject = projectFactory.CreateAndAddToWorkspace( projectSystemName, language, new VisualStudioProjectCreationInfo { // The workspace requires an assembly name so we can make compilations. We'll use // projectSystemName because they'll have a better one eventually. AssemblyName = projectSystemName, FilePath = projectFilePath, Hierarchy = hierarchy, ProjectGuid = GetProjectIDGuid(hierarchy), }); // 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) VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy); Hierarchy = hierarchy; ConnectHierarchyEvents(); RefreshBinOutputPath(); // TODO: remove this terrible hack, which is working around shims throwing in not-good ways try { _externalErrorReporter = new ProjectExternalErrorReporter(VisualStudioProject.Id, externalErrorReportingPrefix, serviceProvider); _editAndContinueProject = new VsENCRebuildableProjectImpl(Workspace, VisualStudioProject, serviceProvider); } catch (Exception) { } _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>(); _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy); }
public AbstractLegacyProject( string projectSystemName, IVsHierarchy hierarchy, string language, IServiceProvider serviceProvider, IThreadingContext threadingContext, string externalErrorReportingPrefix, HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt, ICommandLineParserService commandLineParserServiceOpt) : base(threadingContext, assertIsForeground: true) { Contract.ThrowIfNull(hierarchy); var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); Workspace = componentModel.GetService <VisualStudioWorkspace>(); var workspaceImpl = (VisualStudioWorkspaceImpl)Workspace; var projectFilePath = hierarchy.TryGetProjectFilePath(); if (projectFilePath != null && !File.Exists(projectFilePath)) { projectFilePath = null; } if (projectFilePath != null) { _projectDirectory = Path.GetDirectoryName(projectFilePath); } var projectFactory = componentModel.GetService <VisualStudioProjectFactory>(); VisualStudioProject = projectFactory.CreateAndAddToWorkspace( projectSystemName, language, new VisualStudioProjectCreationInfo { // The workspace requires an assembly name so we can make compilations. We'll use // projectSystemName because they'll have a better one eventually. AssemblyName = projectSystemName, FilePath = projectFilePath, Hierarchy = hierarchy, ProjectGuid = GetProjectIDGuid(hierarchy), }); workspaceImpl.AddProjectRuleSetFileToInternalMaps( VisualStudioProject, () => VisualStudioProjectOptionsProcessor.EffectiveRuleSetFilePath); // 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) VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy); Hierarchy = hierarchy; ConnectHierarchyEvents(); RefreshBinOutputPath(); workspaceImpl.SubscribeExternalErrorDiagnosticUpdateSourceToSolutionBuildEvents(); _externalErrorReporter = new ProjectExternalErrorReporter(VisualStudioProject.Id, externalErrorReportingPrefix, workspaceImpl); _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>(); _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy); }