Пример #1
0
 public void CanCreateUsingFrameworkVersion(FrameworkData data)
 {
     RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);
     Assert.AreEqual(data.runtime, framework.Runtime, "#1");
     Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion, "#2");
     Assert.AreEqual(data.clrVersion, framework.ClrVersion, "#3");
 }
Пример #2
0
        public void CanDisplayFrameworkAsString(FrameworkData data)
        {
            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);

            Assert.That(framework.ToString(), Is.EqualTo(data.representation));
            Assert.That(framework.DisplayName, Is.EqualTo(data.displayName));
        }
Пример #3
0
        public void CanParseRuntimeFramework(FrameworkData data)
        {
            RuntimeFramework framework = RuntimeFramework.Parse(data.representation);

            Assert.That(framework.Runtime, Is.EqualTo(data.runtime));
            Assert.That(framework.ClrVersion, Is.EqualTo(data.clrVersion));
        }
        public void CanDisplayFrameworkAsString(FrameworkData data)
        {
            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);

            Assert.AreEqual(data.representation, framework.ToString());
            Assert.AreEqual(data.displayName, framework.DisplayName);
        }
        public void CanParseRuntimeFramework(FrameworkData data)
        {
            RuntimeFramework framework = RuntimeFramework.Parse(data.representation);

            Assert.AreEqual(data.runtime, framework.Runtime);
            Assert.AreEqual(data.clrVersion, framework.ClrVersion);
        }
Пример #6
0
        public void CanDisplayFrameworkAsString(FrameworkData data)
        {
            RuntimeFramework framework = new RuntimeFramework(data.Runtime, data.FrameworkVersion);

            Assert.AreEqual(data.Representation, framework.ToString(), "#1");
            Assert.AreEqual(data.DisplayName, framework.DisplayName, "#2");
        }
Пример #7
0
        public void CanCreateNewRuntimeFramework(FrameworkData data)
        {
            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);

            Assert.AreEqual(data.runtime, framework.Runtime);
            Assert.AreEqual(data.clrVersion, framework.ClrVersion);
        }
Пример #8
0
        public void CanCreateFromFrameworkName(FrameworkData data)
        {
            Assume.That(data.runtime != Runtime.Mono);

            var framework = RuntimeFramework.FromFrameworkName(data.frameworkName);

            Assert.That(framework.ToString(), Is.EqualTo(data.representation));
        }
Пример #9
0
        public void CanCreateUsingFrameworkVersion(FrameworkData data)
        {
            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);

            Assert.That(framework.Runtime, Is.EqualTo(data.runtime));
            Assert.That(framework.FrameworkVersion, Is.EqualTo(data.frameworkVersion));
            Assert.That(framework.ClrVersion, Is.EqualTo(data.clrVersion));
        }
Пример #10
0
        public void CanCreateUsingFrameworkVersion(FrameworkData data)
        {
            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);

            Assert.AreEqual(data.runtime, framework.Runtime, "#1");
            Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion, "#2");
            Assert.AreEqual(data.clrVersion, framework.ClrVersion, "#3");
        }
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            Assume.That(data.frameworkVersion.Major != 3);

            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);
            Assert.AreEqual(data.runtime, framework.Runtime);
            Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion);
            Assert.AreEqual(data.clrVersion, framework.ClrVersion);
        }
Пример #12
0
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            Assume.That(data.frameworkVersion.Major != 3, "#0");

            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);

            Assert.AreEqual(data.runtime, framework.Runtime, "#1");
            Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion, "#2");
            Assert.AreEqual(data.clrVersion, framework.ClrVersion, "#3");
        }
Пример #13
0
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            // Can't create using CLR version if we expect version 3.0, 3.5 or 4.5
            Assume.That(data.frameworkVersion.Major != 3);
            if (data.frameworkVersion.Major == 4)
                Assume.That(data.frameworkVersion.Minor != 5);

            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);
            Assert.AreEqual(data.runtime, framework.Runtime);
            Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion);
            Assert.AreEqual(data.clrVersion, framework.ClrVersion);
        }
Пример #14
0
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            Assume.That(data.FrameworkVersion.Major != 3, "#0");
            //.NET Framework 4.0+ and .NET Core 2.0+ all have the same CLR version
            Assume.That(data.FrameworkVersion.Major != 4 && data.FrameworkVersion.Minor != 5, "#0");
            Assume.That(data.Runtime != RuntimeType.NetCore, "#0");

            RuntimeFramework framework = new RuntimeFramework(data.Runtime, data.ClrVersion);

            Assert.AreEqual(data.Runtime, framework.Runtime, "#1");
            Assert.AreEqual(data.FrameworkVersion, framework.FrameworkVersion, "#2");
            Assert.AreEqual(data.ClrVersion, framework.ClrVersion, "#3");
        }
Пример #15
0
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            // Versions 3.x and 4.5 or higher can't be created using CLR version
            Assume.That(data.frameworkVersion.Major != 3);
            Assume.That(data.frameworkVersion.Major != 4 || data.frameworkVersion.Minor == 0);

            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);

            Assert.That(framework.Runtime, Is.EqualTo(data.runtime));
            Assert.That(framework.FrameworkVersion, Is.EqualTo(data.frameworkVersion));
            Assert.That(framework.ClrVersion, Is.EqualTo(data.clrVersion));
            Assert.That(framework.FrameworkName, Is.EqualTo(data.frameworkName));
        }
        public FrameworkProject(Project project, FrameworkData frameworkData)
        {
            Project      = project;
            Framework    = frameworkData.FrameworkName;
            FriendlyName = frameworkData.FriendlyName;
            ShortName    = frameworkData.ShortName;
            ProjectId    = ProjectId.CreateNewId();
//            Documents = new Dictionary<string, DocumentId>();
            FileReferences           = new Dictionary <string, MetadataReference>();
            RawReferences            = new Dictionary <string, MetadataReference>();
            ProjectReferences        = new Dictionary <string, ProjectId>(StringComparer.OrdinalIgnoreCase);
            ProjectDependeees        = new Dictionary <string, ProjectId>(StringComparer.OrdinalIgnoreCase);
            PendingProjectReferences = new List <ProjectId>();
        }
Пример #17
0
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            // Can't create using CLR version if we expect version 3.0, 3.5 or 4.5
            Assume.That(data.frameworkVersion.Major != 3);
            if (data.frameworkVersion.Major == 4)
            {
                Assume.That(data.frameworkVersion.Minor != 5);
            }

            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);

            Assert.AreEqual(data.runtime, framework.Runtime);
            Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion);
            Assert.AreEqual(data.clrVersion, framework.ClrVersion);
        }
Пример #18
0
        private State Initialize(string appPath, string configuration, bool triggerBuildOutputs)
        {
            var state = new State
            {
                Frameworks = new List <FrameworkData>(),
                Projects   = new List <ProjectInfo>()
            };

            Project project;

            if (!Project.TryGetProject(appPath, out project))
            {
                throw new InvalidOperationException(string.Format("Unable to find project.json in '{0}'", appPath));
            }

            if (triggerBuildOutputs)
            {
                // Trigger the build outputs for this project
                _namedDependencyProvider.Trigger(project.Name + "_BuildOutputs");
            }

            state.Name           = project.Name;
            state.Configurations = project.GetConfigurations().ToList();
            state.Commands       = project.Commands;

            var frameworks = new List <FrameworkName>(
                project.GetTargetFrameworks()
                .Select(tf => tf.FrameworkName));

            if (!frameworks.Any())
            {
                frameworks.Add(VersionUtility.ParseFrameworkName("aspnet50"));
            }

            var appHostContextCache = new Dictionary <Tuple <string, FrameworkName>, ApplicationHostContext>();

            // We need to create an app env for the design time host's target framework
            var runtimeApplicationHostContext = new ApplicationHostContext(_hostServices,
                                                                           appPath,
                                                                           packagesDirectory: null,
                                                                           configuration: _appEnv.Configuration,
                                                                           targetFramework: _appEnv.RuntimeFramework,
                                                                           cache: _cache,
                                                                           cacheContextAccessor: _cacheContextAccessor,
                                                                           namedCacheDependencyProvider: _namedDependencyProvider);

            runtimeApplicationHostContext.DependencyWalker.Walk(project.Name, project.Version, _appEnv.RuntimeFramework);

            var runtimeAppHostContextCacheKey = Tuple.Create(_appEnv.Configuration, _appEnv.RuntimeFramework);

            // TODO: Move this caching to the ICache
            appHostContextCache[runtimeAppHostContextCacheKey] = runtimeApplicationHostContext;

            foreach (var frameworkName in frameworks)
            {
                var cacheKey = Tuple.Create(configuration, frameworkName);

                ApplicationHostContext applicationHostContext;
                if (!appHostContextCache.TryGetValue(cacheKey, out applicationHostContext))
                {
                    applicationHostContext = new ApplicationHostContext(_hostServices,
                                                                        appPath,
                                                                        packagesDirectory: null,
                                                                        configuration: configuration,
                                                                        targetFramework: frameworkName,
                                                                        cache: _cache,
                                                                        cacheContextAccessor: _cacheContextAccessor,
                                                                        namedCacheDependencyProvider: _namedDependencyProvider,
                                                                        loadContextFactory: runtimeApplicationHostContext.AssemblyLoadContextFactory);

                    applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, frameworkName);

                    appHostContextCache[cacheKey] = applicationHostContext;
                }

                var libraryManager    = applicationHostContext.LibraryManager;
                var metadataProvider  = applicationHostContext.CreateInstance <ProjectMetadataProvider>();
                var frameworkResolver = applicationHostContext.FrameworkReferenceResolver;
                var metadata          = metadataProvider.GetProjectMetadata(project.Name);

                var dependencies = applicationHostContext.DependencyWalker
                                   .Libraries
                                   .Select(CreateDependencyDescription)
                                   .ToDictionary(d => d.Name);

                var projectReferences = applicationHostContext.DependencyWalker
                                        .Libraries
                                        .Where(d => string.Equals(d.Type, "Project") && !string.Equals(d.Identity.Name, project.Name))
                                        .Select(d => new ProjectReference
                {
                    Framework = new FrameworkData
                    {
                        ShortName     = VersionUtility.GetShortFrameworkName(d.Framework),
                        FrameworkName = d.Framework.ToString(),
                        FriendlyName  = frameworkResolver.GetFriendlyFrameworkName(d.Framework)
                    },
                    Path = d.Path
                })
                                        .ToList();

                var frameworkData = new FrameworkData
                {
                    ShortName      = VersionUtility.GetShortFrameworkName(frameworkName),
                    FrameworkName  = frameworkName.ToString(),
                    FriendlyName   = frameworkResolver.GetFriendlyFrameworkName(frameworkName),
                    RedistListPath = frameworkResolver.GetFrameworkRedistListPath(frameworkName)
                };

                state.Frameworks.Add(frameworkData);

                var projectInfo = new ProjectInfo()
                {
                    Path            = appPath,
                    Configuration   = configuration,
                    TargetFramework = frameworkData,
                    FrameworkName   = frameworkName,
                    // TODO: This shouldn't be roslyn specific compilation options
                    CompilationSettings = project.GetCompilationSettings(frameworkName, configuration),
                    Dependencies        = dependencies,
                    ProjectReferences   = projectReferences,
                    Metadata            = metadata,
                    Output = new ProjectOutput()
                };

                var export           = libraryManager.GetLibraryExport(project.Name);
                var projectReference = export.MetadataReferences.OfType <IMetadataProjectReference>()
                                       .First();

                var embeddedReferences = export.MetadataReferences.OfType <IMetadataEmbeddedReference>().Select(r =>
                {
                    return(new
                    {
                        Name = r.Name,
                        Bytes = r.Contents
                    });
                })
                                         .ToDictionary(a => a.Name, a => a.Bytes);

                var engine = new NonLoadingLoadContext();

                if (!metadata.Errors.Any())
                {
                    projectReference.Load(engine);
                }

                projectInfo.Output.AssemblyBytes      = engine.AssemblyBytes ?? new byte[0];
                projectInfo.Output.PdbBytes           = engine.PdbBytes ?? new byte[0];
                projectInfo.Output.AssemblyPath       = engine.AssemblyPath;
                projectInfo.Output.EmbeddedReferences = embeddedReferences;

                state.Projects.Add(projectInfo);

                if (state.ProjectSearchPaths == null)
                {
                    state.ProjectSearchPaths = applicationHostContext.ProjectResolver.SearchPaths.ToList();
                }

                if (state.GlobalJsonPath == null)
                {
                    GlobalSettings settings;
                    if (GlobalSettings.TryGetGlobalSettings(applicationHostContext.RootDirectory, out settings))
                    {
                        state.GlobalJsonPath = settings.FilePath;
                    }
                }
            }

            return(state);
        }
Пример #19
0
        public ProjectState Resolve(string appPath,
                                    string configuration,
                                    bool triggerBuildOutputs,
                                    bool triggerDependencies,
                                    int protocolVersion,
                                    IList <string> currentSearchPaths)
        {
            var state = new ProjectState
            {
                Frameworks  = new List <FrameworkData>(),
                Projects    = new List <ProjectInfo>(),
                Diagnostics = new List <DiagnosticMessage>()
            };

            Project project;

            if (!Project.TryGetProject(appPath, out project, state.Diagnostics))
            {
                throw new InvalidOperationException($"Unable to find project.json in '{appPath}'");
            }

            if (triggerBuildOutputs)
            {
                // Trigger the build outputs for this project
                _compilationEngine.CompilationCache.NamedCacheDependencyProvider.Trigger(project.Name + "_BuildOutputs");
            }

            if (triggerDependencies)
            {
                _compilationEngine.CompilationCache.NamedCacheDependencyProvider.Trigger(project.Name + "_Dependencies");
            }

            state.Name           = project.Name;
            state.Project        = project;
            state.Configurations = project.GetConfigurations().ToList();
            state.Commands       = project.Commands;

            var frameworks = new List <FrameworkName>(project.GetTargetFrameworks().Select(tf => tf.FrameworkName));

            if (!frameworks.Any())
            {
                frameworks.Add(VersionUtility.ParseFrameworkName(FrameworkNames.ShortNames.Dnx451));
            }

            var sourcesProjectWidesources = project.Files.SourceFiles.ToList();

            ResolveSearchPaths(state);

            foreach (var frameworkName in frameworks)
            {
                var dependencyInfo = ResolveProjectDependencies(project,
                                                                configuration,
                                                                frameworkName,
                                                                protocolVersion,
                                                                GetUpdatedSearchPaths(currentSearchPaths, state.ProjectSearchPaths));

                var dependencySources = new List <string>(sourcesProjectWidesources);

                var frameworkData = new FrameworkData
                {
                    ShortName      = VersionUtility.GetShortFrameworkName(frameworkName),
                    FrameworkName  = frameworkName.ToString(),
                    FriendlyName   = _frameworkReferenceResolver.GetFriendlyFrameworkName(frameworkName),
                    RedistListPath = _frameworkReferenceResolver.GetFrameworkRedistListPath(frameworkName)
                };

                state.Frameworks.Add(frameworkData);

                // Add shared files from packages
                dependencySources.AddRange(dependencyInfo.ExportedSourcesFiles);

                // Add shared files from projects
                foreach (var reference in dependencyInfo.ProjectReferences)
                {
                    if (reference.Project == null)
                    {
                        continue;
                    }

                    // Only add direct dependencies as sources
                    if (!project.Dependencies.Any(d => string.Equals(d.Name, reference.Name, StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    dependencySources.AddRange(reference.Project.Files.SharedFiles);
                }

                var projectInfo = new ProjectInfo
                {
                    Path            = appPath,
                    Configuration   = configuration,
                    TargetFramework = frameworkData,
                    FrameworkName   = frameworkName,
                    // TODO: This shouldn't be Roslyn specific compilation options
                    CompilationSettings = project.GetCompilerOptions(frameworkName, configuration)
                                          .ToCompilationSettings(frameworkName, project.ProjectDirectory),
                    SourceFiles    = dependencySources,
                    DependencyInfo = dependencyInfo
                };

                state.Projects.Add(projectInfo);
            }

            return(state);
        }
 public void CanDisplayFrameworkAsString(FrameworkData data)
 {
     RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);
     Assert.AreEqual(data.representation, framework.ToString());
     Assert.AreEqual(data.displayName, framework.DisplayName);
 }
 public void CanParseRuntimeFramework(FrameworkData data)
 {
     RuntimeFramework framework = RuntimeFramework.Parse(data.representation);
     Assert.AreEqual(data.runtime, framework.Runtime);
     Assert.AreEqual(data.clrVersion, framework.ClrVersion);
 }
Пример #22
0
        private State DoInitialWork(string appPath, string configuration, bool triggerBuildOutputs, bool triggerRestoreComplete)
        {
            var state = new State
            {
                Frameworks = new List <FrameworkData>(),
                Projects   = new List <ProjectInfo>()
            };

            Project project;

            if (!Project.TryGetProject(appPath, out project))
            {
                throw new InvalidOperationException(string.Format("Unable to find project.json in '{0}'", appPath));
            }

            if (triggerBuildOutputs)
            {
                // Trigger the build outputs for this project
                _namedDependencyProvider.Trigger(project.Name + "_BuildOutputs");
            }

            if (triggerRestoreComplete)
            {
                _namedDependencyProvider.Trigger(project.Name + "_RestoreComplete");
            }

            state.Name           = project.Name;
            state.Configurations = project.GetConfigurations().ToList();
            state.Commands       = project.Commands;

            var frameworks = new List <FrameworkName>(
                project.GetTargetFrameworks()
                .Select(tf => tf.FrameworkName));

            if (!frameworks.Any())
            {
                frameworks.Add(VersionUtility.ParseFrameworkName("aspnet50"));
            }

            var sourcesProjectWideSources = project.SourceFiles.ToList();

            foreach (var frameworkName in frameworks)
            {
                var dependencyInfo    = ResolveProjectDepencies(project, configuration, frameworkName);
                var dependencySources = new List <string>(sourcesProjectWideSources);

                var frameworkResolver = dependencyInfo.HostContext.FrameworkReferenceResolver;

                var frameworkData = new FrameworkData
                {
                    ShortName      = VersionUtility.GetShortFrameworkName(frameworkName),
                    FrameworkName  = frameworkName.ToString(),
                    FriendlyName   = frameworkResolver.GetFriendlyFrameworkName(frameworkName),
                    RedistListPath = frameworkResolver.GetFrameworkRedistListPath(frameworkName)
                };

                state.Frameworks.Add(frameworkData);

                // Add shared files
                foreach (var reference in dependencyInfo.ProjectReferences)
                {
                    Project referencedProject;
                    if (Project.TryGetProject(reference.Path, out referencedProject))
                    {
                        dependencySources.AddRange(referencedProject.SharedFiles);
                    }
                }

                var projectInfo = new ProjectInfo()
                {
                    Path            = appPath,
                    Configuration   = configuration,
                    TargetFramework = frameworkData,
                    FrameworkName   = frameworkName,
                    // TODO: This shouldn't be roslyn specific compilation options
                    CompilationSettings = project.GetCompilationSettings(frameworkName, configuration),
                    SourceFiles         = dependencySources,
                    DependencyInfo      = dependencyInfo
                };

                state.Projects.Add(projectInfo);

                if (state.ProjectSearchPaths == null)
                {
                    state.ProjectSearchPaths = dependencyInfo.HostContext.ProjectResolver.SearchPaths.ToList();
                }

                if (state.GlobalJsonPath == null)
                {
                    GlobalSettings settings;
                    if (GlobalSettings.TryGetGlobalSettings(dependencyInfo.HostContext.RootDirectory, out settings))
                    {
                        state.GlobalJsonPath = settings.FilePath;
                    }
                }
            }

            return(state);
        }
Пример #23
0
 public void CanCreateNewRuntimeFramework(FrameworkData data)
 {
     RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);
     Assert.AreEqual(data.runtime, framework.Runtime);
     Assert.AreEqual(data.clrVersion, framework.ClrVersion);
 }