命令行编译Win Forms C#应用程序 [英] Command Line Compiling a Win Forms C# Application
问题描述
我试图创建一个脚本从命令行编译Windows窗体C#2.0项目(我知道,我知道..我重新发明轮..再次..但如果有人知道答案,我非常感谢。)
I'm trying to create a script to compile an Windows Forms C# 2.0 project from the command line (I know, I know.. I'm reinventing the wheel.. again.. but if somebody knows the answer, I'd appreciate it).
该项目是一个标准的Windows窗体项目,它有一些资源和引用一对外部程序集。这里是文件的列表:
The project is a standard Windows Forms project that has some resources and references a couple external assemblies. Here is a list of the files:
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
到目前为止,我已经确定了我需要的以下程序/工具:
So far I've identified the following programs/tools that I would need:
csc.exe // the C# compiler
al.exe // the assembly linker
resgen.exe // the resource compiler
到目前为止,这是我的脚本:
And this is my script so far:
@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!!
最后,无论我如何旋转它,我从链接器获得不同的错误,或者最终的可执行文件不会运行崩溃。
In the end, no matter how I spin it I get different errors from the linker, or the final executable will just not run - it crashes.
请帮助(MSDN没有帮助太多..)!
Please help (MSDN didn't help too much..)!
推荐答案
我喜欢欺骗这些东西。执行工作项目并对其运行以下命令
I like to cheat for these kinds of things. Take a working project and run the following command on it
msbuild Project.csproj /t:rebuild /clp:ShowCommandLine
它的输出将显示msbuild用于编译项目的命令,然后您可以将其用作你喜欢。
The output of that will show you the command msbuild uses to compile the project, which you can then take and modify as you like.
这篇关于命令行编译Win Forms C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!