public static FrameworkData ToPayload(this NuGetFramework framework,
                                       FrameworkReferenceResolver resolver)
 {
     return(new FrameworkData
     {
         ShortName = framework.GetShortFolderName(),
         FrameworkName = framework.DotNetFrameworkName,
         FriendlyName = framework.Framework,
         RedistListPath = resolver.GetFrameworkRedistListPath(framework)
     });
 }
Exemple #2
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);
        }