c# - 命令行编译 Win Forms C# 应用程序

标签 c# .net compiler-construction .net-2.0 cmd

我正在尝试创建一个脚本来从命令行编译 Windows 窗体 C# 2.0 项目(我知道,我知道..我正在重新发明轮子..再次..但如果有人知道答案,我不胜感激)。

该项目是一个标准的 Windows 窗体项目,它具有一些资源并引用了几个外部程序集。以下是文件列表:

    Program.cs                  // no need to expand on this on :)
    frmMain.cs                  // this is a typical C# windows forms file
    frmMain.designer.cs         //  .. and the designer code
    frmMain.resx                //  .. and the resource file
    MyClasses.cs                // this contains a couple classes
    Properties\AssemblyInfo.cs        // the Properties folder -- again pretty standard 
    Properties\Resources.Designer.cs
    Properties\Resources.resz
    Properties\Settings.Designer.cs
    Properties\Settings.settings
    References\AnAssembly.dll   // an assmebly that I reference from this application

到目前为止,我已经确定了以下我需要的程序/工具:

    csc.exe      //  the C# compiler
    al.exe       //  the assembly linker
    resgen.exe   //  the resource compiler

到目前为止,这是我的脚本:

    @echo off
    set OUT=Out
    set AL=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\al.exe
    set RESGEN="C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\resgen.exe"
    set COMPILER=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe

    echo.
    echo Compiler: %COMPILER%
    echo.

    if "%1"=="/help" goto help

    :start
    echo Starting...

    set REFERENCES=.\References\AReferencedll
    set SRCFILES=Program.cs frmMain.cs frmMain.designer.cs MyClasses.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs

    del /Q %OUT%\*

    %RESGEN% /compile frmMain.resx,%OUT%\frmMain.resources 

    cd Properties

    %RESGEN% /compile Resources.resx,..\%OUT%\Resources.resources

    cd ..

    %COMPILER% /target:module /out:%OUT%\app.module %SRCFILES% /reference:%REFERENCES%

    %AL% %OUT%\app.module /embed:%OUT%\frmMain.resources /target:winexe /out:%OUT%\app.exe /main:App.Program.Main

    goto done
    :error
    echo Ooooops!

    :done
    echo Done!!

最后,无论我如何旋转它,我都会从链接器中得到不同的错误,或者最终的可执行文件将无法运行 - 它会崩溃。

请帮助(MSDN 没有提供太多帮助..)!

最佳答案

我喜欢为这些事情作弊。获取一个工作项目并在其上运行以下命令

msbuild Project.csproj /t:rebuild /clp:ShowCommandLine

它的输出将显示 msbuild 用于编译项目的命令,然后您可以根据需要进行修改。

关于c# - 命令行编译 Win Forms C# 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/708029/

相关文章:

c# - SetForegroundWindow 在 Windows Server 2008 上失败

java.lang.ArrayIndexOutOfBoundsException : 49 error - NFA Java 异常

c# - .NET Compact Framework - 没有 ShowDialog 的模态表单

C++ 编译器差异

string - 为什么不使用字符串缓冲区而不是不可变字符串?

c# - 表达式树的问题

c# - 在 iText 7 .NET/C# 中为 PDF 创建图像表单域

c# - 缓存 IEnumerable 与 List 以进行延迟初始化

c# - 动态程序集和方法

.net - mysql 查询越远越慢?