示例#1
0
 public void UpdateXaml(string xaml, string sourceAssembly)
 {
     _xaml = new UpdateXamlMessage {
         AssemblyPath = sourceAssembly, Xaml = xaml
     };
     _conn?.Send(_xaml);
 }
示例#2
0
        public void Start(string targetExe, string xaml, string sourceAssembly)
        {
            _xaml = new UpdateXamlMessage {
                Xaml = xaml, AssemblyPath = sourceAssembly
            };
            if (_proc != null)
            {
                _proc.Exited -= OnExited;
                try
                {
                    _conn?.Dispose();
                    _conn = null;
                    _proc.Kill();
                }
                catch { }
                HandleExited();
                State = "Restarting...";
            }

            var netCore    = false;
            var targetDir  = Path.GetDirectoryName(targetExe);
            var targetBase = Path.Combine(targetDir,
                                          Path.GetFileNameWithoutExtension(targetExe));

            var depsJsonPath = targetBase + ".deps.json";

            netCore = File.Exists(depsJsonPath) &&
                      DepsJson.Load(depsJsonPath)?.RuntimeTarget?.Name?.Contains("NETCoreApp") == true;
            var sessionId = Guid.NewGuid().ToString();

            DesignerTcpListener.Register(this, sessionId);
            var cmdline =
                $"--transport tcp-bson://127.0.0.1:{DesignerTcpListener.Port}/ --session-id {sessionId} --method win32 \"{targetExe}\"";

            if (netCore)
            {
                cmdline =
                    $"exec --runtimeconfig \"{targetBase}.runtimeconfig.json\" --depsfile \"{depsJsonPath}\" \"{_config.NetCoreAppHostPath}\" " +
                    cmdline;
            }
            var exe = netCore ? "dotnet" : _config.NetFxAppHostPath;

            _proc = new Process()
            {
                StartInfo = new ProcessStartInfo(exe, cmdline)
                {
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                    WorkingDirectory       = targetDir
                },
                EnableRaisingEvents = true
            };

            _proc.Exited += OnExited;
            try
            {
                _proc.Start();
                SpawnedProcess?.Invoke(_proc);
                State = "Launching designer process: " + Environment.NewLine
                        + exe + " " + cmdline + Environment.NewLine + "from directory " + targetDir;
                StartReaders(_proc);
            }
            catch (Exception e)
            {
                State = e.ToString();
                HandleExited();
            }
            IsAlive = true;
        }