Пример #1
0
        public static void Publish(string project, DotnetPublishSettings settings = null)
        {
            var argbuilder = new StringBuilder();

            argbuilder.Append($"publish {M()} /nr:false");
            if (!string.IsNullOrWhiteSpace(settings?.Configuration))
            {
                argbuilder.Append(" -c ").Append(settings.Configuration);
            }
            if (!string.IsNullOrWhiteSpace(settings?.OutputDirectory))
            {
                argbuilder.Append(" -o ").Append(P(settings.OutputDirectory));
            }
            if (!string.IsNullOrWhiteSpace(settings?.Runtime))
            {
                argbuilder.Append(" -r ").Append(settings.Runtime);
            }
            if (settings != null && settings.SelfContained)
            {
                argbuilder.Append(" --self-contained true");
            }
            argbuilder.Append(" ").Append(P(project));
            RunCommand("dotnet", argbuilder.ToString());
        }
Пример #2
0
        public static void PatchedPublish(string proj, string outputDirectory, string rid)
        {
            Directory.CreateDirectory(outputDirectory);
            string publishDir = Path.Combine(outputDirectory, "lib");
            //Publish
            var publishSettings = new DotnetPublishSettings
            {
                Configuration   = "Release",
                OutputDirectory = publishDir,
                SelfContained   = true,
                Runtime         = rid
            };

            Dotnet.Publish(proj, publishSettings);
            //Delete junk files
            DeleteFilesGlob(publishDir,
                            "*.pdb",
                            "createdump",
                            "SOS_README.md"
                            );
            //TODO: Fix this msbuild side
            if (rid == "win7-x86")
            {
                RmDir(Path.Combine(publishDir, "x64"));
            }
            if (rid == "win7-x64")
            {
                RmDir(Path.Combine(publishDir, "x86"));
            }
            //Move the AppHost
            var apphostName = Path.GetFileNameWithoutExtension(proj);
            var origName    = apphostName + ".dll";

            if (IsWindows)
            {
                apphostName += ".exe";
            }
            string appHostPath = Path.Combine(outputDirectory, apphostName);

            if (File.Exists(appHostPath))
            {
                File.Delete(appHostPath);
            }
            File.Move(Path.Combine(publishDir, apphostName), appHostPath);
            //Patch the AppHost
            var origPathBytes = Encoding.UTF8.GetBytes(origName + "\0");
            var libDir        = IsWindows ? "lib\\" : "lib/";
            var newPath       = libDir + origName;
            var newPathBytes  = Encoding.UTF8.GetBytes(newPath + "\0");
            var apphostExe    = File.ReadAllBytes(appHostPath);
            int offset        = FindBytes(apphostExe, origPathBytes);

            if (offset < 0)
            {
                throw new Exception("Could not patch apphost " + appHostPath);
            }
            for (int i = 0; i < newPathBytes.Length; i++)
            {
                apphostExe[offset + i] = newPathBytes[i];
            }
            File.WriteAllBytes(appHostPath, apphostExe);
        }