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

命令行编译Win Forms C#应用程序,c#,.net,compiler-construction,.net-2.0,cmd,C#,.net,Compiler Construction,.net 2.0,Cmd,我正试图创建一个脚本来从命令行编译一个Windows Forms C#2.0项目(我知道,我知道..我正在重新发明轮子..再一次..如果有人知道答案,我将不胜感激) 该项目是一个标准的Windows窗体项目,它有一些资源并引用了几个外部程序集。以下是文件列表: Program.cs // no need to expand on this on :) frmMain.cs // this is a typical C#

我正试图创建一个脚本来从命令行编译一个Windows Forms 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 Program.cs//无需在此基础上展开:) frmMain.cs//这是一个典型的C#windows窗体文件 frmMain.designer.cs/。。和设计器代码 frmMain.resx/。。和资源文件 MyClasses.cs//这包含两个类 Properties\AssemblyInfo.cs//Properties文件夹——同样是非常标准的 属性\Resources.Designer.cs Properties\Resources.resz 属性\Settings.Designer.cs 属性\Settings.Settings References\anasembly.dll//我从此应用程序引用的组件 到目前为止,我已经确定了我需要的以下程序/工具:

csc.exe // the C# compiler al.exe // the assembly linker resgen.exe // the resource compiler csc.exe//C#编译器 al.exe//程序集链接器 resgen.exe//资源编译器 这是我目前的剧本:

@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!! @回音 出发 设置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 回声。 回显编译器:%1编译器% 回声。 如果“%1”=“/help”转到帮助 :开始 回音开始。。。 设置引用=。\REFERENCES\areferencedl 设置SRCFILES=Program.cs frmMain.cs frmMain.designer.cs MyClasses.cs Properties\AssemblyInfo.cs Properties\Resources.designer.cs Properties\Settings.designer.cs 删除/质量百分比输出%\* %RESGEN%/编译frmMain.resx,%OUT%\frmMain.resources cd属性 %RESGEN%/compile Resources.resx,..\%OUT%\Resources.Resources 光盘 %编译器%/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 好了 :错误 回声呜呜! :完成 回音完成!! 最后,无论我如何旋转它,我都会从链接器中得到不同的错误,否则最终的可执行文件将无法运行——它会崩溃


请帮忙(MSDN帮不了多少忙…)

不使用msbuild有什么原因吗?它可以在一个命令中编译任何visual studio项目/解决方案

msbuild.exe <solution filename>
msbuild.exe
只需使用传入解决方案或项目文件即可


使用MSBuild的最佳方法是通过VisualStudio命令提示符;它为您设置所有必需的环境变量。SDK中也提供了此命令设置。

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

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

该命令的输出将向您显示msbuild用于编译项目的命令,然后您可以随意获取和修改该命令。

Scott,谢谢您的提示。。这确实有帮助,但是我的版本中仍然有错误。如果我运行msbuild,它会生成可执行文件,但是如果我手动尝试并运行命令,则生成的可执行文件在尝试使用ResourceManager查找资源时会抛出错误。。!?!