Beispiel #1
0
 protected void Init()
 {
     try
     {
         Workspace = new AdhocWorkspace();
         Workspace.AddSolution(SolutionInfo.Create(MSSolutionID.CreateNewId(), VersionStamp.Default));
         References = new List <string>(DefaultReferences);
     }
     catch (ReflectionTypeLoadException ex)
     {
         StringBuilder sb = new StringBuilder();
         foreach (Exception exSub in ex.LoaderExceptions)
         {
             sb.AppendLine(exSub.Message);
             if (exSub is FileNotFoundException exFileNotFound)
             {
                 if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                 {
                     sb.AppendLine("Fusion Log:");
                     sb.AppendLine(exFileNotFound.FusionLog);
                 }
             }
             sb.AppendLine();
         }
         string errorMessage = sb.ToString();
         //Display or log the error based on your application.
         throw;
     }
 }
Beispiel #2
0
        /// <summary>
        /// This method is called when the solution is removed from the workspace.
        ///
        /// Override this method if you want to do additional work when the solution is removed.
        /// Call the base method at the end of your method.
        /// Call this method to respond to a solution being removed/cleared/closed in the host environment.
        /// </summary>
        protected internal void OnSolutionRemoved()
        {
            using (this.serializationLock.DisposableWait())
            {
                var oldSolution = this.CurrentSolution;

                this.ClearSolutionData();

                // reset to new empty solution
                this.SetCurrentSolution(this.CreateSolution(SolutionId.CreateNewId()));

                this.RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind.SolutionRemoved, oldSolution, this.CurrentSolution);

                // At this point, no one will need to pull any more items out of the old solution,
                // so clear all objects out of the caches. but this has to run after the workspace event
                // since the workspace event holds onto old solution which makes most of items in the cache alive
                // also, here we don't clear text cache since doing that right after clearing out other caches
                // make us to dump evicted texts unnecessarily to MMF. instead, we will let the text to be eventually
                // replaced with new texts and those texts belong to old solution will be removed without being written to MMF
                this.ScheduleTask(() =>
                {
                    this.workspaceServicesProvider.GetService <ICompilationCacheService>().Clear();
                    this.workspaceServicesProvider.GetService <ISyntaxTreeCacheService>().Clear();
                }, "Workspace.ClearCache");
            }
        }
 // Initialization
 public static Project CreateFakeProject()
 {
     return(new AdhocWorkspace()
            .AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), null, null, null))
            .AddProject("FakeProject", "FakeProject", LanguageNames.CSharp)
            .AddMetadataReferences(Basic.Reference.Assemblies.Net50.All)
            .WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)));
 }
Beispiel #4
0
        internal Workspace(IWorkspaceServiceProvider workspaceServicesProvider)
        {
            this.primaryBranchId = BranchId.GetNextId();

            this.workspaceServicesProvider = workspaceServicesProvider;

            // queue used for sending events
            var workspaceTaskSchedulerFactory = workspaceServicesProvider.GetService <IWorkspaceTaskSchedulerFactory>();

            this.taskQueue = workspaceTaskSchedulerFactory.CreateTaskQueue();

            // initialize with empty solution
            this.latestSolution = CreateSolution(SolutionId.CreateNewId());
        }
Beispiel #5
0
        /// <summary>
        /// Constructs a new workspace instance.
        /// </summary>
        /// <param name="host">The <see cref="HostServices"/> this workspace uses</param>
        /// <param name="workspaceKind">A string that can be used to identify the kind of workspace. Usually this matches the name of the class.</param>
        protected Workspace(HostServices host, string workspaceKind)
        {
            this.primaryBranchId = BranchId.GetNextId();
            this.workspaceKind   = workspaceKind;

            this.services = host.CreateWorkspaceServices(this);

            // queue used for sending events
            var workspaceTaskSchedulerFactory = this.services.GetService <IWorkspaceTaskSchedulerFactory>();

            this.taskQueue = workspaceTaskSchedulerFactory.CreateTaskQueue();

            // initialize with empty solution
            this.latestSolution = CreateSolution(SolutionId.CreateNewId());
        }