/// <summary> /// Builds a stub EXE that executes the "0install run" command. /// </summary> /// <param name="target">The application to be launched via the stub.</param> /// <param name="path">The target path to store the generated EXE file.</param> /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param> /// <param name="needsTerminal"><see langword="true"/> to build a CLI stub, <see langword="false"/> to build a GUI stub.</param> /// <param name="command">The command argument to be passed to the the "0install run" command; can be <see langword="null"/>.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="InvalidOperationException">There was a compilation error while generating the stub EXE.</exception> /// <exception cref="IOException">A problem occurs while writing to the filesystem.</exception> /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem is not permitted.</exception> internal static void BuildRunStub(this FeedTarget target, [NotNull] string path, [NotNull] ITaskHandler handler, bool needsTerminal, [CanBeNull] string command = null) { #region Sanity checks if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); if (handler == null) throw new ArgumentNullException("handler"); #endregion var compilerParameters = new CompilerParameters { GenerateExecutable = true, OutputAssembly = path, IncludeDebugInformation = false, GenerateInMemory = false, TreatWarningsAsErrors = true, ReferencedAssemblies = {"System.dll"} }; if (!needsTerminal) compilerParameters.CompilerOptions += " /target:winexe"; var icon = target.Feed.GetIcon(Icon.MimeTypeIco, command); if (icon != null) { string iconPath = IconCacheProvider.GetInstance().GetIcon(icon.Href, handler); compilerParameters.CompilerOptions += " /win32icon:" + iconPath.EscapeArgument(); } compilerParameters.CompileCSharp( GetRunStubCode(target, needsTerminal, command), typeof(StubBuilder).GetEmbedded("Stub.manifest").ReadToString()); }