private async Task NotifyIdeAboutDotNetSources(int executionContextId, JObject auxData)
        {
            // Add all the .pdb files from the client bin dir
            // TODO: Don't do it based on files on disk. Instead, somehow know what assemblies
            // have been referenced in client-side code, and use that as the list.
            _debugInfoStore.AddPdbFiles(_clientBinDir);

            // Also add .pdb files corresponding to the compiled Razor views
            // It's a bit lame to rely on the compiled assembly already being cached like this,
            // but we don't have all the info needed to compile it freshly here (e.g., list of
            // assembly references).
            var compiledViewsAssemblyData = RazorCompilation.GetCachedCompiledAssembly(_clientViewsAssemblyName);

            if (compiledViewsAssemblyData.Item1 != null)
            {
                using (var peStream = new MemoryStream(compiledViewsAssemblyData.Item1))
                    using (var pdbStream = new MemoryStream(compiledViewsAssemblyData.Item2))
                    {
                        _debugInfoStore.AddPdb(peStream, pdbStream);
                    }
            }

            foreach (var sourceFile in _debugInfoStore.SourceFiles)
            {
                await NotifyBrowserAboutScript(executionContextId, auxData, sourceFile);
            }
        }
Ejemplo n.º 2
0
        private static Assembly GetCompiledViewsAssembly(string rootPath, string appAssemblyName, string[] referenceAssemblies)
        {
            var viewsAssemblyName = appAssemblyName.Replace(".dll", $".{ ++viewAssemblyCount }.Views.dll");
            var viewAssemblyBytes = RazorCompilation.GetCompiledViewsAssembly(
                rootPath,
                viewsAssemblyName,
                referenceAssemblies);

            using (var ms = new MemoryStream(viewAssemblyBytes))
            {
                return(AssemblyLoadContext.Default.LoadFromStream(ms));
            }
        }
        public static void UseWdbServer(this IApplicationBuilder applicationBuilder, string rootDir, string clientBinDir)
        {
            applicationBuilder.Use((context, next) =>
            {
                var pathString = context.Request.Path.Value;
                if (pathString.EndsWith(".wdb"))
                {
                    context.Response.ContentType = "application/octet-stream";

                    var pdbFilename = Path.Combine(clientBinDir, Path.ChangeExtension(Path.GetFileName(pathString), "pdb"));
                    if (File.Exists(pdbFilename))
                    {
                        using (var peStream = File.OpenRead(Path.ChangeExtension(pdbFilename, "dll")))
                            using (var pdbStream = File.OpenRead(pdbFilename))
                            {
                                WdbWriter.WriteSequencePointsToFile(peStream, pdbStream, context.Response.Body);
                            }
                    }
                    else if (context.Request.Query["type"] == "razorviews")
                    {
                        // Use the in-memory compiled views
                        var compiledAssembly = RazorCompilation.GetCompiledViewsAssembly(rootDir, context.Request);
                        using (var peStream = new MemoryStream(compiledAssembly.Item1))
                            using (var pdbStream = new MemoryStream(compiledAssembly.Item2))
                            {
                                WdbWriter.WriteSequencePointsToFile(peStream, pdbStream, context.Response.Body);
                            }
                    }
                    else
                    {
                        // If we lack a PDB file, just serve an empty .wdb so it's not a runtime error
                        // The effect will be that you can't set breakpoints on this file or step into it.
                        context.Response.Body.WriteByte(0);
                    }

                    return(Task.CompletedTask);
                }

                return(next());
            });
        }