Пример #1
0
        private void WritePackageContents(string tempPath, bool pomonaClientEmbeddingEnabled)
        {
            Directory.CreateDirectory(tempPath);
            Directory.CreateDirectory(Path.Combine(tempPath, "lib"));
            var dllDir = Path.Combine(tempPath, "lib", "net40");

            Directory.CreateDirectory(dllDir);
            var dllPath = Path.Combine(dllDir, this.typeMapper.Filter.ClientMetadata.AssemblyName + ".dll");

            using (var stream = File.Create(dllPath))
            {
                var pomonaClientXmlDocPath = Path.Combine(dllDir, Path.GetFileNameWithoutExtension(dllPath) + ".xml");
                ClientLibGenerator.WriteClientLibrary(this.typeMapper, stream, pomonaClientEmbeddingEnabled,
                                                      () => File.OpenWrite(pomonaClientXmlDocPath));
            }

            if (pomonaClientEmbeddingEnabled)
            {
                return;
            }

            var pomonaClientAssemblySourcePath = typeof(RootResource <>).Assembly.Location;
            var pomonaClientAssemblyDestPath   = Path.Combine(dllDir, Path.GetFileName(pomonaClientAssemblySourcePath));

            File.Copy(pomonaClientAssemblySourcePath, pomonaClientAssemblyDestPath);
        }
Пример #2
0
        private Response GetClientLibrary()
        {
            byte[] bytes;
            using (var memstream = new MemoryStream())
            {
                ClientLibGenerator.WriteClientLibrary(TypeMapper, memstream);
                bytes = memstream.ToArray();
            }

            var response = new Response
            {
                Contents    = stream => stream.Write(bytes, 0, bytes.Length),
                ContentType = "binary/octet-stream"
            };

            return(response);
        }
Пример #3
0
        private static int WriteClientLibrary(string dllName, TypeMapper typeMapper)
        {
            try
            {
                dllName = Path.GetFullPath(dllName);
                Console.WriteLine("Writing DLL to {0}", dllName);
                var xmlDocName = Path.Combine(Path.GetDirectoryName(dllName), Path.GetFileNameWithoutExtension(dllName) + ".xml");

                // Avoid modifying existing xml doc file while Visual studio is reading it.
                if (File.Exists(xmlDocName))
                {
                    File.Delete(xmlDocName);
                }
                using (var file = new FileStream(dllName, FileMode.OpenOrCreate))
                {
                    if (!dllName.EndsWith(".dll"))
                    {
                        throw new ArgumentException("Filename should end with .dll");
                    }
                    ClientLibGenerator.WriteClientLibrary(typeMapper, file, xmlDocStreamFactory: () => File.OpenWrite(xmlDocName),
                                                          assemblyTransformHook: TransformAssemblyHook);
                }
            }
            catch (Exception exception)
            {
                if (exception.UnableToLoadAssemblyFromFileShare(dllName))
                {
                    Console.WriteLine($"ERROR! The file '{dllName}' seems to be pointing to a file share, which Mono.Cecil is unable to resolve during build time, for weird and unbeknownst reasons.");
                    return(0);
                }

                Console.WriteLine(exception);
                return(1);
            }

            return(0);
        }