protected override async Task OnProjectChangedAsync()
        {
            ForegroundDispatcher.AssertBackgroundThread();

            await ExecuteWithLockAsync(async() =>
            {
                var referencedAssemblies = await DotNetProject.GetReferencedAssemblies(ConfigurationSelector.Default);
                var mvcReference         = referencedAssemblies.FirstOrDefault(IsMvcAssembly);

                if (mvcReference == null)
                {
                    // Ok we can't find an MVC version. Let's assume this project isn't using Razor then.
                    await UpdateHostProjectUnsafeAsync(null).ConfigureAwait(false);
                    return;
                }

                var version = GetAssemblyVersion(mvcReference.FilePath);
                if (version == null)
                {
                    // Ok we can't find an MVC version. Let's assume this project isn't using Razor then.
                    await UpdateHostProjectUnsafeAsync(null).ConfigureAwait(false);
                    return;
                }

                var configuration = FallbackRazorConfiguration.SelectConfiguration(version);
                var hostProject   = new HostProject(DotNetProject.FileName.FullPath, configuration);
                await UpdateHostProjectUnsafeAsync(hostProject).ConfigureAwait(false);
            });
        }
        protected override async Task OnProjectChangedAsync()
        {
            await ExecuteWithLockAsync(async() =>
            {
                var referencedAssemblies = await DotNetProject.GetReferencedAssemblies(ConfigurationSelector.Default);
                var mvcReference         = referencedAssemblies.FirstOrDefault(IsMvcAssembly);
                var projectProperties    = DotNetProject.MSBuildProject.EvaluatedProperties;

                if (TryGetIntermediateOutputPath(projectProperties, out var intermediatePath))
                {
                    var projectConfigurationFile = Path.Combine(intermediatePath, _languageServerFeatureOptions.ProjectConfigurationFileName);
                    ProjectConfigurationFilePathStore.Set(DotNetProject.FileName.FullPath, projectConfigurationFile);
                }

                if (mvcReference is null)
                {
                    // Ok we can't find an MVC version. Let's assume this project isn't using Razor then.
                    await UpdateHostProjectUnsafeAsync(null).ConfigureAwait(false);
                    return;
                }

                var version = GetAssemblyVersion(mvcReference.FilePath);
                if (version is null)
                {
                    // Ok we can't find an MVC version. Let's assume this project isn't using Razor then.
                    await UpdateHostProjectUnsafeAsync(null).ConfigureAwait(false);
                    return;
                }

                var configuration = FallbackRazorConfiguration.SelectConfiguration(version);
                var hostProject   = new HostProject(DotNetProject.FileName.FullPath, configuration, rootNamespace: null);
                await UpdateHostProjectUnsafeAsync(hostProject).ConfigureAwait(false);
            });
        }
Exemplo n.º 3
0
        static async Task AddAssemblyReference(MonoDevelopWorkspace ws, DotNetProject from, DotNetProject to, string name)
        {
            var manager = ws.MetadataReferenceManager;

            var assemblies = await from.GetReferencedAssemblies(IdeApp.Workspace?.ActiveConfiguration ?? ConfigurationSelector.Default);

            var messagingAsm      = assemblies.Single(x => x.Metadata.GetValue <string> ("Filename") == name);
            var metadataReference = manager.GetOrCreateMetadataReference(messagingAsm.FilePath, MetadataReferenceProperties.Assembly);

            await FileWatcherService.Update();

            var roslynProj = ws.GetProjectId(to);

            var oldRefs     = ws.CurrentSolution.GetProject(roslynProj).MetadataReferences;
            var newRefs     = oldRefs.ToImmutableArray().Add(metadataReference.CurrentSnapshot);
            var newSolution = ws.CurrentSolution.WithProjectMetadataReferences(roslynProj, newRefs);

            Assert.IsTrue(ws.TryApplyChanges(newSolution));
            await ws.ProjectSaveTask;

            var reference = to.References.Single(x => x.Include == name);

            Assert.IsTrue(reference.HintPath.IsNull);
            Assert.AreEqual(ReferenceType.Package, reference.ReferenceType);
        }
        public void UpdateFromProject()
        {
            Hashtable fs = new Hashtable();

            foreach (ProjectFile file in project.Files)
            {
                if (GetFile(file.Name) == null)
                {
                    AddFile(file.Name);
                }
                fs [file.Name] = null;
            }

            foreach (string file in files.Keys.ToArray())
            {
                if (!fs.Contains(file))
                {
                    RemoveFile(file);
                }
            }

            fs.Clear();
            if (project is DotNetProject)
            {
                DotNetProject netProject = (DotNetProject)project;
                foreach (SolutionItem pr in netProject.GetReferencedItems(ConfigurationSelector.Default))
                {
                    if (pr is Project)
                    {
                        string refId = "Project:" + ((Project)pr).FileName;
                        fs[refId] = null;
                        if (!HasReference(refId))
                        {
                            AddReference(refId);
                        }
                    }
                }

                // Get the assembly references throught the project, since it may have custom references
                foreach (string file in netProject.GetReferencedAssemblies(ConfigurationSelector.Default, false))
                {
                    string refId = "Assembly:" + netProject.TargetRuntime.Id + ":" + Path.GetFullPath(file);
                    fs[refId] = null;
                    if (!HasReference(refId))
                    {
                        AddReference(refId);
                    }
                }
            }

            foreach (ReferenceEntry re in References)
            {
                // Don't delete corlib references. They are implicit to projects, but not to pidbs.
                if (!fs.Contains(re.Uri) && !IsCorlibReference(re))
                {
                    RemoveReference(re.Uri);
                }
            }
            UpdateCorlibReference();
        }
Exemplo n.º 5
0
        async Task RunTests(DotNetProject project)
        {
            await project.ClearCachedData();

            var config = IdeApp.Workspace.ActiveConfiguration ?? ConfigurationSelector.Default;

            using (var timer = new SimpleTimer(LogView, project, "GetReferencedAssemblies")) {
                var results = await project.GetReferencedAssemblies(config, false);
            }

            using (var timer = new SimpleTimer(LogView, project, "GetSourceFilesAsync")) {
                var sources = await project.GetSourceFilesAsync(config);
            }
        }