Example #1
0
 public RuntimeLibraryManager(ApplicationHostContext applicationHostContext)
 {
     _libraryManager = new Lazy<LibraryManager>(() =>
     {
         ApplicationHostContext.Initialize(applicationHostContext);
         return applicationHostContext.LibraryManager;
     });
 }
Example #2
0
        private LibraryManager CreateLibraryManager()
        {
            var hostContext = new ApplicationHostContext
            {
                Project = _options.Project,
                TargetFramework = _framework
            };

            ApplicationHostContext.Initialize(hostContext);

            return hostContext.LibraryManager;
        }
Example #3
0
 public AssemblyWalker(
     FrameworkName framework,
     ApplicationHostContext hostContext,
     string runtimeFolder,
     bool showDetails,
     Reports reports)
 {
     _framework = framework;
     _hostContext = hostContext;
     _runtimeFolder = runtimeFolder;
     _showDetails = showDetails;
     _reports = reports;
 }
    static IEnumerable<LibraryDescription> GetAllDeps(Project proj) =>
      proj.GetTargetFrameworks().Select(f => f.FrameworkName)
        .SelectMany(f =>
        {
          var context = new ApplicationHostContext
          {
            Project = proj,
            TargetFramework = f
          };

          return ApplicationHostContext.GetRuntimeLibraries(context).Skip(1); // the first one is the self-reference
        })
        .Distinct(LibraryUtils.Comparer)
        .OrderBy(l => l.Identity?.Name);
Example #5
0
        public DependencyContext(Runtime.Project project, FrameworkName targetFramework)
        {
            var applicationHostContext = new ApplicationHostContext
            {
                Project = project,
                TargetFramework = targetFramework
            };

            ApplicationHostContext.Initialize(applicationHostContext);

            FrameworkName = targetFramework;
            LibraryManager = applicationHostContext.LibraryManager;
            PackagesDirectory = applicationHostContext.PackagesDirectory;
        }
Example #6
0
        public static IList <LibraryDescription> GetRuntimeLibraries(ApplicationHostContext context, bool throwOnInvalidLockFile)
        {
            var result = InitializeCore(context);

            if (throwOnInvalidLockFile)
            {
                if (!result.ValidLockFile)
                {
                    throw new InvalidOperationException($"{result.LockFileValidationMessage}. Please run \"dnu restore\" to generate a new lock file.");
                }
            }

            return(result.Libraries);
        }
Example #7
0
        private RuntimeLoadContext InitializeProjectLoadContext()
        {
            // Create an application host context to use to drive a Load Context used to load Precompilers
            var context = new ApplicationHostContext
            {
                Project = _project,
                RuntimeIdentifiers = _compilationEngineContext.RuntimeEnvironment.GetAllRuntimeIdentifiers(),
                TargetFramework = _compilationEngineContext.ApplicationEnvironment.RuntimeFramework
            };

            var libraries = ApplicationHostContext.GetRuntimeLibraries(context);

            return new RuntimeLoadContext($"{_project.Name}_build", libraries, _compilationEngine, _compilationEngineContext.DefaultLoadContext);
        }
Example #8
0
        public static IList<LibraryDescription> GetRuntimeLibraries(ApplicationHostContext context, bool throwOnInvalidLockFile)
        {
            var result = InitializeCore(context);

            if (throwOnInvalidLockFile)
            {
                if (!result.ValidLockFile)
                {
                    throw new InvalidOperationException($"{result.LockFileValidationMessage}. Please run \"dnu restore\" to generate a new lock file.");
                }
            }

            return result.Libraries;
        }
        public ModuleLoaderContext(
            string projectDirectory,
            FrameworkName targetFramework)
        {
            var applicationHostContext = new ApplicationHostContext {
                ProjectDirectory = projectDirectory,
                TargetFramework = targetFramework
            };

            ApplicationHostContext.Initialize(applicationHostContext);

            LibraryManager = applicationHostContext.LibraryManager;
            Project = applicationHostContext.Project;
            TargetFramework = applicationHostContext.TargetFramework;
        }
Example #10
0
        public LibraryExporter CreateProjectExporter(Project project, FrameworkName targetFramework, string configuration)
        {
            // This library manager represents the graph that will be used to resolve
            // references (compiler /r in csc terms)

            var context = new ApplicationHostContext
            {
                Project = project,
                TargetFramework = targetFramework
            };

            ApplicationHostContext.Initialize(context);

            return new LibraryExporter(context.LibraryManager, this, configuration);
        }
Example #11
0
        private ApplicationHostContext CreateApplicationHostContext()
        {
            var accessor = new CacheContextAccessor();
            var cache = new Cache(accessor);

            var hostContext = new ApplicationHostContext(
                hostServices: null,
                projectDirectory: _options.Project.ProjectDirectory,
                packagesDirectory: null,
                configuration: Configuration,
                targetFramework: _framework);

            hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, _framework);

            return hostContext;
        }
Example #12
0
        public LibraryManager GetProjectGraph(Project project, FrameworkName targetFramework)
        {
            // TODO: Cache sub-graph walk?

            // Create a child app context for this graph walk
            var context = new ApplicationHostContext
            {
                Project = project,
                TargetFramework = targetFramework
            };

            ApplicationHostContext.Initialize(context);

            // Return the results
            return context.LibraryManager;
        }
Example #13
0
        public LibraryManager GetProjectGraph(Project project, FrameworkName targetFramework)
        {
            // TODO: Cache sub-graph walk?

            // Create a child app context for this graph walk
            var context = new ApplicationHostContext
            {
                Project         = project,
                TargetFramework = targetFramework
            };

            ApplicationHostContext.Initialize(context);

            // Return the results
            return(context.LibraryManager);
        }
Example #14
0
        public DependencyContext(Runtime.Project project, FrameworkName targetFramework, IEnumerable<string> runtimeIdentifiers)
        {
            var applicationHostContext = new ApplicationHostContext
            {
                Project = project,
                TargetFramework = targetFramework,
                RuntimeIdentifiers = runtimeIdentifiers
            };

            ApplicationHostContext.Initialize(applicationHostContext);

            FrameworkName = targetFramework;
            LibraryManager = applicationHostContext.LibraryManager;
            PackagesDirectory = applicationHostContext.PackagesDirectory;
            RuntimeIdentifiers = runtimeIdentifiers;
        }
Example #15
0
        public IEnumerable <LibraryDescription> GetProjectGraph(Project project, FrameworkName targetFramework, string configuration)
        {
            // TODO: Cache sub-graph walk?

            // Create a child app context for this graph walk
            var context = new ApplicationHostContext(
                _hostServices,
                project.ProjectDirectory,
                packagesDirectory: null,
                configuration: configuration,
                targetFramework: targetFramework);

            // Walk the graph
            context.DependencyWalker.Walk(project.Name, project.Version, targetFramework);

            // Return the results
            return(context.DependencyWalker.Libraries);
        }
Example #16
0
        public IEnumerable<LibraryDescription> GetProjectGraph(Project project, FrameworkName targetFramework, string configuration)
        {
            // TODO: Cache sub-graph walk?

            // Create a child app context for this graph walk
            var context = new ApplicationHostContext(
                _hostServices,
                project.ProjectDirectory,
                packagesDirectory: null,
                configuration: configuration,
                targetFramework: targetFramework);

            // Walk the graph
            context.DependencyWalker.Walk(project.Name, project.Version, targetFramework);

            // Return the results
            return context.DependencyWalker.Libraries;
        }
Example #17
0
        public DependencyContext(string projectDirectory, string configuration, FrameworkName targetFramework)
        {
            var cacheContextAccessor = new CacheContextAccessor();
            var cache = new Cache(cacheContextAccessor);

            var applicationHostContext = new ApplicationHostContext(
                hostServices: null,
                projectDirectory: projectDirectory,
                packagesDirectory: null,
                configuration: configuration,
                targetFramework: targetFramework);

            ProjectResolver = applicationHostContext.ProjectResolver;
            NuGetDependencyResolver = applicationHostContext.NuGetDependencyProvider;
            ProjectReferenceDependencyProvider = applicationHostContext.ProjectDependencyProvider;
            DependencyWalker = applicationHostContext.DependencyWalker;
            FrameworkName = targetFramework;
            PackagesDirectory = applicationHostContext.PackagesDirectory;
        }
        public IAssemblyLoadContext Create(IServiceProvider serviceProvider)
        {
            var hostContextKey = Tuple.Create("RuntimeLoadContext", _project.Name, _appEnv.Configuration, _appEnv.RuntimeFramework);

            var appHostContext = _compilationFactory.CompilationCache.Cache.Get<ApplicationHostContext>(hostContextKey, ctx =>
            {
                var applicationHostContext = new ApplicationHostContext(serviceProvider,
                                                                        _project.ProjectDirectory,
                                                                        packagesDirectory: null,
                                                                        configuration: _appEnv.Configuration,
                                                                        targetFramework: _appEnv.RuntimeFramework);

                applicationHostContext.DependencyWalker.Walk(_project.Name, _project.Version, _appEnv.RuntimeFramework);

                // Watch all projects for project.json changes
                foreach (var library in applicationHostContext.DependencyWalker.Libraries)
                {
                    if (string.Equals(library.Type, "Project"))
                    {
                        ctx.Monitor(new FileWriteTimeCacheDependency(library.Path));
                    }
                }

                // Add a cache dependency on restore complete to reevaluate dependencies
                ctx.Monitor(_compilationFactory.CompilationCache.NamedCacheDependencyProvider.GetNamedDependency(_project.Name + "_Dependencies"));

                // Create compilation engine and add it to the services
                var compilationEngine = _compilationFactory.CreateEngine(new CompilationEngineContext(
                    applicationHostContext.LibraryManager,
                    applicationHostContext.ProjectGraphProvider,
                    NoopWatcher.Instance,
                    applicationHostContext.ServiceProvider,
                    _appEnv.RuntimeFramework,
                    _appEnv.Configuration));
                applicationHostContext.AddService(typeof(ICompilationEngine), compilationEngine);

                return applicationHostContext;
            });

            var factory = new AssemblyLoadContextFactory(appHostContext.ServiceProvider);
            return factory.Create(appHostContext.ServiceProvider);
        }
Example #19
0
        private static void AddLockFileDiagnostics(ApplicationHostContext context, Result result)
        {
            if (!result.LockFileExists)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                                                                DiagnosticMonikers.NU1009,
                                                                $"The expected lock file doesn't exist. Please run \"dnu restore\" to generate a new lock file.",
                                                                Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                                                                DiagnosticMessageSeverity.Error));
            }

            if (!result.ValidLockFile)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                                                                DiagnosticMonikers.NU1006,
                                                                $"{result.LockFileValidationMessage}. Please run \"dnu restore\" to generate a new lock file.",
                                                                Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                                                                DiagnosticMessageSeverity.Error));
            }
        }
Example #20
0
        private static LockFileTarget SelectTarget(ApplicationHostContext context, LockFile lockFile)
        {
            foreach (var runtimeIdentifier in context.RuntimeIdentifiers)
            {
                foreach (var scanTarget in lockFile.Targets)
                {
                    if (scanTarget.TargetFramework == context.TargetFramework && string.Equals(scanTarget.RuntimeIdentifier, runtimeIdentifier, StringComparison.Ordinal))
                    {
                        return(scanTarget);
                    }
                }
            }

            foreach (var scanTarget in lockFile.Targets)
            {
                if (scanTarget.TargetFramework == context.TargetFramework && string.IsNullOrEmpty(scanTarget.RuntimeIdentifier))
                {
                    return(scanTarget);
                }
            }

            return(null);
        }
 static IEnumerable<LibraryDescription> GetAllDeps(Project proj) =>
     proj.GetTargetFrameworks().Select(f => f.FrameworkName)
     .SelectMany(f =>
     {
         var context = new ApplicationHostContext
         {
             Project = proj,
             TargetFramework = f
         };
         IList<LibraryDescription> libs = null;
         while (libs == null) {
             try
             {
                 libs = ApplicationHostContext.GetRuntimeLibraries(context);
             }
             catch (Exception e)
             {
             }
         }
         // the first library description is always self-reference, so skip it
         return libs.Skip(1);
     })
     .Distinct(LibraryUtils.Comparer)
     .OrderBy(l => l.Identity?.Name);
Example #22
0
        private void Initialize(RuntimeOptions options, IServiceProvider hostServices, IAssemblyLoadContextAccessor loadContextAccessor, IFileWatcher fileWatcher)
        {
            _applicationHostContext = new ApplicationHostContext(
                hostServices,
                _projectDirectory,
                options.PackageDirectory,
                options.Configuration,
                _targetFramework);

            _compilationEngine = _compilationEngineFactory.CreateEngine(
                new CompilationEngineContext(
                    _applicationHostContext.LibraryManager,
                    _applicationHostContext.ProjectGraphProvider,
                    fileWatcher,
                    _applicationHostContext.ServiceProvider,
                    _targetFramework,
                    options.Configuration));

            // Make the root project's library exports available for apps to read.
            _applicationHostContext.AddService(typeof(ILibraryExporter), _compilationEngine.RootLibraryExporter);
            _applicationHostContext.AddService(typeof(ICompilationEngine), _compilationEngine);

            Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory);
            Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory);
            Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, _applicationHostContext.Configuration);
            Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory);

            _project = _applicationHostContext.Project;

            if (Project == null)
            {
                throw new Exception("Unable to locate " + Project.ProjectFileName);
            }

            if (options.WatchFiles)
            {
                fileWatcher.OnChanged += _ =>
                {
                    _shutdown.RequestShutdownWaitForDebugger();
                };
            }

            _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown);
            _applicationHostContext.AddService(typeof(RuntimeOptions), options);

            if (options.CompilationServerPort.HasValue)
            {
                // Change the project reference provider
                Project.DefaultCompiler = Project.DefaultDesignTimeCompiler;
            }

            CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider;

            // Configure Assembly loaders
            _loaders.Add(new ProjectAssemblyLoader(
                loadContextAccessor,
                _applicationHostContext.ProjectResolver,
                _compilationEngine));
            _loaders.Add(new NuGetAssemblyLoader(loadContextAccessor, _applicationHostContext.NuGetDependencyProvider));
        }
Example #23
0
 public static IList <LibraryDescription> GetRuntimeLibraries(ApplicationHostContext context)
 {
     return(GetRuntimeLibraries(context, throwOnInvalidLockFile: false));
 }
Example #24
0
        private static LockFileTarget SelectTarget(ApplicationHostContext context, LockFile lockFile)
        {
            foreach (var runtimeIdentifier in context.RuntimeIdentifiers)
            {
                foreach (var scanTarget in lockFile.Targets)
                {
                    if (scanTarget.TargetFramework == context.TargetFramework && string.Equals(scanTarget.RuntimeIdentifier, runtimeIdentifier, StringComparison.Ordinal))
                    {
                        return scanTarget;
                    }
                }
            }

            foreach (var scanTarget in lockFile.Targets)
            {
                if (scanTarget.TargetFramework == context.TargetFramework && string.IsNullOrEmpty(scanTarget.RuntimeIdentifier))
                {
                    return scanTarget;
                }
            }

            return null;
        }
Example #25
0
        public static void Initialize(ApplicationHostContext context)
        {
            var result = InitializeCore(context);

            // Map dependencies
            var lookup = result.Libraries.ToDictionary(l => l.Identity.Name);

            var frameworkReferenceResolver          = context.FrameworkResolver ?? new FrameworkReferenceResolver();
            var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver);
            var gacDependencyResolver        = new GacDependencyResolver();
            var unresolvedDependencyProvider = new UnresolvedDependencyProvider();

            // Fix up dependencies
            foreach (var library in lookup.Values.ToList())
            {
                if (string.Equals(library.Type, LibraryTypes.Package) &&
                    !Directory.Exists(library.Path))
                {
                    // If the package path doesn't exist then mark this dependency as unresolved
                    library.Resolved = false;
                }

                library.Framework = library.Framework ?? context.TargetFramework;
                foreach (var dependency in library.Dependencies)
                {
                    LibraryDescription dep;
                    if (!lookup.TryGetValue(dependency.Name, out dep))
                    {
                        if (dependency.LibraryRange.IsGacOrFrameworkReference)
                        {
                            dep = referenceAssemblyDependencyResolver.GetDescription(dependency.LibraryRange, context.TargetFramework) ??
                                  gacDependencyResolver.GetDescription(dependency.LibraryRange, context.TargetFramework) ??
                                  unresolvedDependencyProvider.GetDescription(dependency.LibraryRange, context.TargetFramework);

                            dep.Framework           = context.TargetFramework;
                            lookup[dependency.Name] = dep;
                        }
                        else
                        {
                            dep = unresolvedDependencyProvider.GetDescription(dependency.LibraryRange, context.TargetFramework);
                            lookup[dependency.Name] = dep;
                        }
                    }

                    // REVIEW: This isn't quite correct but there's a many to one relationship here.
                    // Different ranges can resolve to this dependency but only one wins
                    dep.RequestedRange = dependency.LibraryRange;
                    dependency.Library = dep;
                }
            }

            var libraries = lookup.Values.ToList();

            context.LibraryManager = new LibraryManager(context.Project.ProjectFilePath, context.TargetFramework, libraries);

            AddLockFileDiagnostics(context, result);

            // Clear all the temporary memory aggressively here if we don't care about reuse
            // e.g. runtime scenarios
            lookup.Clear();
        }
Example #26
0
        public static void Initialize(ApplicationHostContext context)
        {
            var result = InitializeCore(context);

            // Map dependencies
            var lookup = result.Libraries.ToDictionary(l => l.Identity.Name);

            var frameworkReferenceResolver = context.FrameworkResolver ?? new FrameworkReferenceResolver();
            var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver);
            var gacDependencyResolver = new GacDependencyResolver();
            var unresolvedDependencyProvider = new UnresolvedDependencyProvider();

            // Fix up dependencies
            foreach (var library in lookup.Values.ToList())
            {
                if (string.Equals(library.Type, LibraryTypes.Package) &&
                    !Directory.Exists(library.Path))
                {
                    // If the package path doesn't exist then mark this dependency as unresolved
                    library.Resolved = false;
                }

                library.Framework = library.Framework ?? context.TargetFramework;
                foreach (var dependency in library.Dependencies)
                {
                    LibraryDescription dep;
                    if (!lookup.TryGetValue(dependency.Name, out dep))
                    {
                        if (dependency.LibraryRange.IsGacOrFrameworkReference)
                        {
                            dep = referenceAssemblyDependencyResolver.GetDescription(dependency.LibraryRange, context.TargetFramework) ??
                                  gacDependencyResolver.GetDescription(dependency.LibraryRange, context.TargetFramework) ??
                                  unresolvedDependencyProvider.GetDescription(dependency.LibraryRange, context.TargetFramework);

                            dep.Framework = context.TargetFramework;
                            lookup[dependency.Name] = dep;
                        }
                        else
                        {
                            dep = unresolvedDependencyProvider.GetDescription(dependency.LibraryRange, context.TargetFramework);
                            lookup[dependency.Name] = dep;
                        }
                    }

                    // REVIEW: This isn't quite correct but there's a many to one relationship here.
                    // Different ranges can resolve to this dependency but only one wins
                    dep.RequestedRange = dependency.LibraryRange;
                    dependency.Library = dep;
                }
            }

            var libraries = lookup.Values.ToList();

            context.LibraryManager = new LibraryManager(context.Project.ProjectFilePath, context.TargetFramework, libraries);

            AddLockFileDiagnostics(context, result);

            // Clear all the temporary memory aggressively here if we don't care about reuse
            // e.g. runtime scenarios
            lookup.Clear();
        }
Example #27
0
        private void Initialize(DefaultHostOptions options, IAssemblyLoadContextAccessor loadContextAccessor)
        {
            var applicationHostContext = new ApplicationHostContext
            {
                ProjectDirectory = _projectDirectory,
                RuntimeIdentifiers = _runtimeEnvironment.GetAllRuntimeIdentifiers(),
                TargetFramework = _targetFramework
            };

            var libraries = ApplicationHostContext.GetRuntimeLibraries(applicationHostContext, throwOnInvalidLockFile: true);

            Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory);
            Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory);
            Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration);
            Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory);

            _applicationHostContext = applicationHostContext;

            _project = applicationHostContext.Project;

#if FEATURE_DNX_MIN_VERSION_CHECK
            ValidateMinRuntimeVersion(libraries);
#endif

            // Create a new Application Environment for running the app. It needs a reference to the Host's application environment
            // (if any), which we can get from the service provider we were given.
            // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating
            // will just have it's own independent set of global data.
            var hostEnvironment = PlatformServices.Default.Application;
            var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, hostEnvironment);

            var compilationContext = new CompilationEngineContext(
                applicationEnvironment,
                _runtimeEnvironment,
                loadContextAccessor.Default,
                new CompilationCache());

            var compilationEngine = new CompilationEngine(compilationContext);
            var runtimeLibraryExporter = new RuntimeLibraryExporter(() => compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration));

            var runtimeLibraryManager = new RuntimeLibraryManager(applicationHostContext);

            // Default services
            _serviceProvider.Add(typeof(ILibraryExporter), runtimeLibraryExporter);
            _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment);
            _serviceProvider.Add(typeof(IRuntimeEnvironment), PlatformServices.Default.Runtime);
            _serviceProvider.Add(typeof(ILibraryManager), runtimeLibraryManager);
            _serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), PlatformServices.Default.AssemblyLoadContextAccessor);
            _serviceProvider.Add(typeof(IAssemblyLoaderContainer), PlatformServices.Default.AssemblyLoaderContainer);
            
            PlatformServices.SetDefault(new ApplicationHostPlatformServices(PlatformServices.Default, applicationEnvironment, runtimeLibraryManager));

            if (options.CompilationServerPort.HasValue)
            {
                // Change the project reference provider
                Project.DefaultCompiler = Project.DefaultDesignTimeCompiler;
                Project.DesignTimeCompilerPort = options.CompilationServerPort.Value;
            }

            // TODO: Dedupe this logic in the RuntimeLoadContext
            var projects = libraries.Where(p => p.Type == Runtime.LibraryTypes.Project)
                                    .ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p);

            var assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);

            // Configure Assembly loaders
            _loaders.Add(new ProjectAssemblyLoader(loadContextAccessor, compilationEngine, projects.Values, options.Configuration));
            _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, assemblies, libraries));

            var compilerOptionsProvider = new CompilerOptionsProvider(projects);

            _serviceProvider.Add(typeof(ICompilerOptionsProvider), compilerOptionsProvider);

            CompilationServices.SetDefault(
                    CompilationServices.Create(
                            libraryExporter: runtimeLibraryExporter,
                            compilerOptionsProvider: compilerOptionsProvider
                        )
                );

#if DNX451
            PackageDependencyProvider.EnableLoadingNativeLibraries(libraries);
#endif
            AddBreadcrumbs(libraries);
        }
Example #28
0
 public DependencyListOperation(DependencyListOptions options, FrameworkName framework)
 {
     _options = options;
     _framework = framework;
     _hostContext = CreateApplicationHostContext();
 }
Example #29
0
 public static IList<LibraryDescription> GetRuntimeLibraries(ApplicationHostContext context)
 {
     return GetRuntimeLibraries(context, throwOnInvalidLockFile: false);
 }
Example #30
0
        internal void AddCompiler(string compilerDirectory)
        {
            DebugMessage("EdgeAssemblyLoadContext::AddCompiler (CLR) - Adding the compiler in {0}", compilerDirectory);

            ApplicationHostContext compilerHostContext = new ApplicationHostContext
            {
                ProjectDirectory = compilerDirectory,
                TargetFramework = TargetFrameworkName
            };

            IList<LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(compilerHostContext);
            Dictionary<AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);

            AddCompileAssemblies(libraries);

            _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries));

            DebugMessage("EdgeAssemblyLoadContext::AddCompiler (CLR) - Finished");
        }
Example #31
0
        public static void Initialize(ApplicationHostContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.ProjectDirectory = context.Project?.ProjectDirectory ?? context.ProjectDirectory;
            context.RootDirectory    = context.RootDirectory ?? ProjectResolver.ResolveRootDirectory(context.ProjectDirectory);
            var projectResolver            = new ProjectResolver(context.ProjectDirectory, context.RootDirectory);
            var frameworkReferenceResolver = context.FrameworkResolver ?? new FrameworkReferenceResolver();

            context.PackagesDirectory = context.PackagesDirectory ?? PackageDependencyProvider.ResolveRepositoryPath(context.RootDirectory);

            var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver);
            var gacDependencyResolver        = new GacDependencyResolver();
            var projectDependencyProvider    = new ProjectReferenceDependencyProvider(projectResolver);
            var unresolvedDependencyProvider = new UnresolvedDependencyProvider();

            IList <IDependencyProvider> dependencyProviders = null;
            LockFileLookup lockFileLookup = null;

            if (context.Project == null)
            {
                Project project;
                if (Project.TryGetProject(context.ProjectDirectory, out project))
                {
                    context.Project = project;
                }
                else
                {
                    throw new InvalidOperationException($"Unable to resolve project from {context.ProjectDirectory}");
                }
            }

            var    projectLockJsonPath       = Path.Combine(context.ProjectDirectory, LockFileReader.LockFileName);
            var    lockFileExists            = File.Exists(projectLockJsonPath);
            var    validLockFile             = false;
            var    skipLockFileValidation    = context.SkipLockfileValidation;
            string lockFileValidationMessage = null;

            if (lockFileExists)
            {
                var lockFileReader = new LockFileReader();
                var lockFile       = lockFileReader.Read(projectLockJsonPath);
                validLockFile = lockFile.IsValidForProject(context.Project, out lockFileValidationMessage);

                // When the only invalid part of a lock file is version number,
                // we shouldn't skip lock file validation because we want to leave all dependencies unresolved, so that
                // VS can be aware of this version mismatch error and automatically do restore
                skipLockFileValidation = context.SkipLockfileValidation && (lockFile.Version == Constants.LockFileVersion);

                if (validLockFile || skipLockFileValidation)
                {
                    lockFileLookup = new LockFileLookup(lockFile);
                    var packageDependencyProvider = new PackageDependencyProvider(context.PackagesDirectory, lockFileLookup);

                    dependencyProviders = new IDependencyProvider[] {
                        projectDependencyProvider,
                        packageDependencyProvider,
                        referenceAssemblyDependencyResolver,
                        gacDependencyResolver,
                        unresolvedDependencyProvider
                    };
                }
            }

            if ((!validLockFile && !skipLockFileValidation) || !lockFileExists)
            {
                // We don't add the PackageDependencyProvider to DependencyWalker
                // It will leave all NuGet packages unresolved and give error message asking users to run "dnu restore"
                dependencyProviders = new IDependencyProvider[] {
                    projectDependencyProvider,
                    referenceAssemblyDependencyResolver,
                    gacDependencyResolver,
                    unresolvedDependencyProvider
                };
            }

            var libraries = DependencyWalker.Walk(dependencyProviders, context.Project.Name, context.Project.Version, context.TargetFramework);

            context.LibraryManager = new LibraryManager(context.Project.ProjectFilePath, context.TargetFramework, libraries);

            if (!validLockFile)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                                                                $"{lockFileValidationMessage}. Please run \"dnu restore\" to generate a new lock file.",
                                                                Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                                                                DiagnosticMessageSeverity.Error));
            }

            if (!lockFileExists)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                                                                $"The expected lock file doesn't exist. Please run \"dnu restore\" to generate a new lock file.",
                                                                Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                                                                DiagnosticMessageSeverity.Error));
            }

            // Clear all the temporary memory aggressively here if we don't care about reuse
            // e.g. runtime scenarios
            lockFileLookup?.Clear();
            projectResolver.Clear();
        }
Example #32
0
        private static Result InitializeCore(ApplicationHostContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.ProjectDirectory = context.Project?.ProjectDirectory ?? context.ProjectDirectory;
            context.RootDirectory = context.RootDirectory ?? ProjectRootResolver.ResolveRootDirectory(context.ProjectDirectory);
            context.PackagesDirectory = context.PackagesDirectory ?? PackageDependencyProvider.ResolveRepositoryPath(context.RootDirectory);

            LockFileLookup lockFileLookup = null;

            if (context.Project == null)
            {
                Project project;
                if (Project.TryGetProject(context.ProjectDirectory, out project))
                {
                    context.Project = project;
                }
                else
                {
                    throw new InvalidOperationException($"Unable to resolve project from {context.ProjectDirectory}");
                }
            }

            var projectLockJsonPath = Path.Combine(context.ProjectDirectory, LockFileReader.LockFileName);

            if (context.LockFile == null && File.Exists(projectLockJsonPath))
            {
                var lockFileReader = new LockFileReader();
                context.LockFile = lockFileReader.Read(projectLockJsonPath);
            }

            var validLockFile = true;
            string lockFileValidationMessage = null;

            if (context.LockFile != null)
            {
                validLockFile = (context.LockFile.Version == Constants.LockFileVersion) && context.LockFile.IsValidForProject(context.Project, out lockFileValidationMessage);

                lockFileLookup = new LockFileLookup(context.LockFile);
            }

            var libraries = new List<LibraryDescription>();
            var packageResolver = new PackageDependencyProvider(context.PackagesDirectory);
            var projectResolver = new ProjectDependencyProvider();

            context.MainProject = projectResolver.GetDescription(context.TargetFramework, context.Project);

            // Add the main project
            libraries.Add(context.MainProject);

            if (lockFileLookup != null)
            {
                var target = SelectTarget(context, context.LockFile);
                if (target != null)
                {
                    if (Logger.IsEnabled && string.IsNullOrEmpty(target.RuntimeIdentifier))
                    {
                        // REVIEW(anurse): Is there ever a reason we want to use the RID-less target now?
                        Logger.TraceWarning($"[{nameof(ApplicationHostContext)}] Lock File Target is Runtime-agnostic! This is generally not good.");
                    }

                    Logger.TraceInformation($"[{nameof(ApplicationHostContext)}] Using Lock File Target: {target.TargetFramework}/{target.RuntimeIdentifier}");
                    foreach (var library in target.Libraries)
                    {
                        if (string.Equals(library.Type, "project"))
                        {
                            var projectLibrary = lockFileLookup.GetProject(library.Name);

                            var path = Path.GetFullPath(Path.Combine(context.ProjectDirectory, projectLibrary.Path));

                            var projectDescription = projectResolver.GetDescription(library.Name, path, library);

                            libraries.Add(projectDescription);
                        }
                        else
                        {
                            var packageEntry = lockFileLookup.GetPackage(library.Name, library.Version);

                            var packageDescription = packageResolver.GetDescription(packageEntry, library);

                            libraries.Add(packageDescription);
                        }
                    }
                }
            }

            lockFileLookup?.Clear();

            var lockFilePresent = context.LockFile != null;
            context.LockFile = null; // LockFile is no longer needed

            return new Result(libraries, lockFilePresent, validLockFile, lockFileValidationMessage);
        }
Example #33
0
        public static void Initialize(ApplicationHostContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.ProjectDirectory = context.Project?.ProjectDirectory ?? context.ProjectDirectory;
            context.RootDirectory = context.RootDirectory ?? ProjectResolver.ResolveRootDirectory(context.ProjectDirectory);
            var projectResolver = new ProjectResolver(context.ProjectDirectory, context.RootDirectory);
            var frameworkReferenceResolver = context.FrameworkResolver ?? new FrameworkReferenceResolver();
            context.PackagesDirectory = context.PackagesDirectory ?? PackageDependencyProvider.ResolveRepositoryPath(context.RootDirectory);

            var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver);
            var gacDependencyResolver = new GacDependencyResolver();
            var projectDependencyProvider = new ProjectReferenceDependencyProvider(projectResolver);
            var unresolvedDependencyProvider = new UnresolvedDependencyProvider();

            IList<IDependencyProvider> dependencyProviders = null;
            LockFileLookup lockFileLookup = null;

            if (context.Project == null)
            {
                Project project;
                if (Project.TryGetProject(context.ProjectDirectory, out project))
                {
                    context.Project = project;
                }
                else
                {
                    throw new InvalidOperationException($"Unable to resolve project from {context.ProjectDirectory}");
                }
            }

            var projectLockJsonPath = Path.Combine(context.ProjectDirectory, LockFileReader.LockFileName);
            var lockFileExists = File.Exists(projectLockJsonPath);
            var validLockFile = false;
            var skipLockFileValidation = context.SkipLockfileValidation;
            string lockFileValidationMessage = null;

            if (lockFileExists)
            {
                var lockFileReader = new LockFileReader();
                var lockFile = lockFileReader.Read(projectLockJsonPath);
                validLockFile = lockFile.IsValidForProject(context.Project, out lockFileValidationMessage);

                // When the only invalid part of a lock file is version number,
                // we shouldn't skip lock file validation because we want to leave all dependencies unresolved, so that
                // VS can be aware of this version mismatch error and automatically do restore
                skipLockFileValidation = context.SkipLockfileValidation && (lockFile.Version == Constants.LockFileVersion);

                if (validLockFile || skipLockFileValidation)
                {
                    lockFileLookup = new LockFileLookup(lockFile);
                    var packageDependencyProvider = new PackageDependencyProvider(context.PackagesDirectory, lockFileLookup);

                    dependencyProviders = new IDependencyProvider[] {
                        projectDependencyProvider,
                        packageDependencyProvider,
                        referenceAssemblyDependencyResolver,
                        gacDependencyResolver,
                        unresolvedDependencyProvider
                    };
                }
            }

            if ((!validLockFile && !skipLockFileValidation) || !lockFileExists)
            {
                // We don't add the PackageDependencyProvider to DependencyWalker
                // It will leave all NuGet packages unresolved and give error message asking users to run "dnu restore"
                dependencyProviders = new IDependencyProvider[] {
                    projectDependencyProvider,
                    referenceAssemblyDependencyResolver,
                    gacDependencyResolver,
                    unresolvedDependencyProvider
                };
            }

            var libraries = DependencyWalker.Walk(dependencyProviders, context.Project.Name, context.Project.Version, context.TargetFramework);

            context.LibraryManager = new LibraryManager(context.Project.ProjectFilePath, context.TargetFramework, libraries);

            if (!validLockFile)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                    $"{lockFileValidationMessage}. Please run \"dnu restore\" to generate a new lock file.",
                    Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                    DiagnosticMessageSeverity.Error));
            }

            if (!lockFileExists)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                    $"The expected lock file doesn't exist. Please run \"dnu restore\" to generate a new lock file.",
                    Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                    DiagnosticMessageSeverity.Error));
            }

            // Clear all the temporary memory aggressively here if we don't care about reuse
            // e.g. runtime scenarios
            lockFileLookup?.Clear();
            projectResolver.Clear();
        }
Example #34
0
        private void Initialize(RuntimeOptions options, IServiceProvider hostServices, IAssemblyLoadContextAccessor loadContextAccessor, IFileWatcher fileWatcher)
        {
            var applicationHostContext = new ApplicationHostContext
            {
                ProjectDirectory = _projectDirectory,
                TargetFramework = _targetFramework
            };

            ApplicationHostContext.Initialize(applicationHostContext);

            Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory);
            Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory);
            Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration);
            Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory);

            _libraryManager = applicationHostContext.LibraryManager;

            _project = applicationHostContext.Project;

            if (options.WatchFiles)
            {
                fileWatcher.OnChanged += _ =>
                {
                    _shutdown.RequestShutdownWaitForDebugger();
                };
            }

            // Create a new Application Environment for running the app. It needs a reference to the Host's application environment
            // (if any), which we can get from the service provider we were given.
            // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating
            // will just have it's own independent set of global data.
            var hostEnvironment = (IApplicationEnvironment)hostServices.GetService(typeof(IApplicationEnvironment));
            var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration, hostEnvironment);

            var compilationContext = new CompilationEngineContext(applicationEnvironment, loadContextAccessor.Default, new CompilationCache(), fileWatcher, new ProjectGraphProvider());

            // Compilation services available only for runtime compilation
            compilationContext.AddCompilationService(typeof(RuntimeOptions), options);
            compilationContext.AddCompilationService(typeof(IApplicationShutdown), _shutdown);

            var compilationEngine = new CompilationEngine(compilationContext);

            // Default services
            _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment);
            _serviceProvider.Add(typeof(ILibraryManager), _libraryManager);

            // TODO: Make this lazy
            _serviceProvider.Add(typeof(ILibraryExporter), compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration));
            _serviceProvider.Add(typeof(IApplicationShutdown), _shutdown);
            _serviceProvider.Add(typeof(ICompilerOptionsProvider), new CompilerOptionsProvider(_libraryManager));

            if (options.CompilationServerPort.HasValue)
            {
                // Change the project reference provider
                Project.DefaultCompiler = Project.DefaultDesignTimeCompiler;
            }

            CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider;

            // Configure Assembly loaders
            _loaders.Add(new ProjectAssemblyLoader(
                loadContextAccessor,
                compilationEngine,
                _libraryManager));

            _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, _libraryManager));
        }
Example #35
0
        private static Result InitializeCore(ApplicationHostContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.ProjectDirectory  = context.Project?.ProjectDirectory ?? context.ProjectDirectory;
            context.RootDirectory     = context.RootDirectory ?? ProjectRootResolver.ResolveRootDirectory(context.ProjectDirectory);
            context.PackagesDirectory = context.PackagesDirectory ?? PackageDependencyProvider.ResolveRepositoryPath(context.RootDirectory);

            LockFileLookup lockFileLookup = null;

            if (context.Project == null)
            {
                Project project;
                if (Project.TryGetProject(context.ProjectDirectory, out project))
                {
                    context.Project = project;
                }
                else
                {
                    throw new InvalidOperationException($"Unable to resolve project from {context.ProjectDirectory}");
                }
            }

            var projectLockJsonPath = Path.Combine(context.ProjectDirectory, LockFileReader.LockFileName);

            if (context.LockFile == null && File.Exists(projectLockJsonPath))
            {
                var lockFileReader = new LockFileReader();
                context.LockFile = lockFileReader.Read(projectLockJsonPath);
            }

            var    validLockFile             = true;
            string lockFileValidationMessage = null;

            if (context.LockFile != null)
            {
                validLockFile = (context.LockFile.Version == Constants.LockFileVersion) && context.LockFile.IsValidForProject(context.Project, out lockFileValidationMessage);

                lockFileLookup = new LockFileLookup(context.LockFile);
            }

            var libraries       = new List <LibraryDescription>();
            var packageResolver = new PackageDependencyProvider(context.PackagesDirectory);
            var projectResolver = new ProjectDependencyProvider();

            context.MainProject = projectResolver.GetDescription(context.TargetFramework, context.Project);

            // Add the main project
            libraries.Add(context.MainProject);

            if (lockFileLookup != null)
            {
                var target = SelectTarget(context, context.LockFile);
                if (target != null)
                {
                    if (Logger.IsEnabled && string.IsNullOrEmpty(target.RuntimeIdentifier))
                    {
                        // REVIEW(anurse): Is there ever a reason we want to use the RID-less target now?
                        Logger.TraceWarning($"[{nameof(ApplicationHostContext)}] Lock File Target is Runtime-agnostic! This is generally not good.");
                    }

                    Logger.TraceInformation($"[{nameof(ApplicationHostContext)}] Using Lock File Target: {target.TargetFramework}/{target.RuntimeIdentifier}");
                    foreach (var library in target.Libraries)
                    {
                        if (string.Equals(library.Type, "project"))
                        {
                            var projectLibrary = lockFileLookup.GetProject(library.Name);

                            var path = Path.GetFullPath(Path.Combine(context.ProjectDirectory, projectLibrary.Path));

                            var projectDescription = projectResolver.GetDescription(library.Name, path, library);

                            libraries.Add(projectDescription);
                        }
                        else
                        {
                            var packageEntry = lockFileLookup.GetPackage(library.Name, library.Version);

                            var packageDescription = packageResolver.GetDescription(packageEntry, library);

                            libraries.Add(packageDescription);
                        }
                    }
                }
            }

            lockFileLookup?.Clear();

            var lockFilePresent = context.LockFile != null;

            context.LockFile = null; // LockFile is no longer needed

            return(new Result(libraries, lockFilePresent, validLockFile, lockFileValidationMessage));
        }
Example #36
0
        public EdgeAssemblyLoadContext(EdgeAssemblyLoadContextAccessor loadContextAccessor)
        {
            DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Starting");
            DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Application root is {0}", RuntimeEnvironment.ApplicationDirectory);

            _loadContextAccessor = loadContextAccessor;

            if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "project.lock.json")))
            {
                IList<LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(ApplicationHostContext);
                Dictionary<string, ProjectDescription> projects = libraries.Where(p => p.Type == LibraryTypes.Project).ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p);
                Dictionary<AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);
                
                CompilationEngineContext compilationContext = new CompilationEngineContext(ApplicationEnvironment, RuntimeEnvironment, this, new CompilationCache());
                CompilationEngine compilationEngine = new CompilationEngine(compilationContext);

                AddCompileAssemblies(libraries);

                _loaders.Add(new ProjectAssemblyLoader(_loadContextAccessor, compilationEngine, projects.Values));
                _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries));
            }

            else
            {
                _noProjectJsonFile = true;

                if (File.Exists(Path.Combine(RuntimeEnvironment.EdgeNodePath, "project.lock.json")))
                {
                    ApplicationHostContext stockHostContext = new ApplicationHostContext
                    {
                        ProjectDirectory = RuntimeEnvironment.EdgeNodePath,
                        TargetFramework = TargetFrameworkName
                    };

                    IList<LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(stockHostContext);
                    Dictionary<AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);

                    AddCompileAssemblies(libraries);

                    _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries));
                }
            }

            DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Created the dependency providers for the application");
        }
        private static ApplicationHostContext GetApplicationHostContext(DnxProject project, string configuration, FrameworkName frameworkName)
        {
            var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, frameworkName);

            return cache.Get<ApplicationHostContext>(cacheKey, ctx =>
            {
                var applicationHostContext = new ApplicationHostContext
                {
                    ProjectDirectory = project.ProjectDirectory,
                    TargetFramework = frameworkName
                };

                ApplicationHostContext.Initialize(applicationHostContext);

                return applicationHostContext;
            });
        }
Example #38
0
    public static void Initialize(IntPtr context, IntPtr exception)
    {
        try
        {
            DebugMessage("CoreCLREmbedding::Initialize (CLR) - Starting");

            RuntimeEnvironment = new EdgeRuntimeEnvironment(Marshal.PtrToStructure<EdgeBootstrapperContext>(context));

            Project project;
            Project.TryGetProject(RuntimeEnvironment.ApplicationDirectory, out project);

            ApplicationHostContext = new ApplicationHostContext
            {
                ProjectDirectory = RuntimeEnvironment.ApplicationDirectory,
                TargetFramework = TargetFrameworkName,
                Project = project
            };

            ApplicationEnvironment = new ApplicationEnvironment(ApplicationHostContext.Project, TargetFrameworkName, "Release", null);
            LoadContextAccessor = new EdgeAssemblyLoadContextAccessor();

            EdgeServiceProvider serviceProvider = new EdgeServiceProvider();

            serviceProvider.Add(typeof(IRuntimeEnvironment), RuntimeEnvironment);
            serviceProvider.Add(typeof(IApplicationEnvironment), ApplicationEnvironment);
            serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), LoadContextAccessor);

            CallContextServiceLocator.Locator = new EdgeServiceProviderLocator
            {
                ServiceProvider = serviceProvider
            };

            PlatformServices.SetDefault(PlatformServices.Create(null, ApplicationEnvironment, RuntimeEnvironment, null, LoadContextAccessor, null));

            DebugMessage("CoreCLREmbedding::Initialize (CLR) - Complete");
        }

        catch (Exception e)
        {
            DebugMessage("CoreCLREmbedding::Initialize (CLR) - Exception was thrown: {0}", e.Message);

            V8Type v8Type;
            Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
        }
    }
Example #39
0
        private static void AddLockFileDiagnostics(ApplicationHostContext context, Result result)
        {
            if (!result.LockFileExists)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                    DiagnosticMonikers.NU1009,
                    $"The expected lock file doesn't exist. Please run \"dnu restore\" to generate a new lock file.",
                    Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                    DiagnosticMessageSeverity.Error));
            }

            if (!result.ValidLockFile)
            {
                context.LibraryManager.AddGlobalDiagnostics(new DiagnosticMessage(
                    DiagnosticMonikers.NU1006,
                    $"{result.LockFileValidationMessage}. Please run \"dnu restore\" to generate a new lock file.",
                    Path.Combine(context.Project.ProjectDirectory, LockFileReader.LockFileName),
                    DiagnosticMessageSeverity.Error));
            }
        }