本文整理汇总了C#中System.CodeDom.Compiler.CompilerParameters.CompileCSharp方法的典型用法代码示例。如果您正苦于以下问题:C# CompilerParameters.CompileCSharp方法的具体用法?C# CompilerParameters.CompileCSharp怎么用?C# CompilerParameters.CompileCSharp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.Compiler.CompilerParameters
的用法示例。
在下文中一共展示了CompilerParameters.CompileCSharp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildRunStub
/// <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());
}