命令行编译 Win Forms C# 应用程序
我正在尝试创建一个脚本来从命令行编译 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 没有提供太多帮助..)!
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).
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.
Please help (MSDN didn't help too much..)!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我喜欢为这类事情作弊。 获取一个工作项目并对其运行以下命令。
该命令的输出将向您显示 msbuild 用于编译该项目的命令,然后您可以根据需要进行修改。
I like to cheat for these kinds of things. Take a working project and run the following command on it
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.
您不使用 msbuild 有什么原因吗? 它可以用一个命令编译任何 Visual Studio 项目/解决方案...
Is there a reason why you are not using msbuild? It can compile any visual studio project/solution in one command...
只需使用 MSBuild 传入解决方案或项目文件即可。
使用 MSBuild 的最佳方法是通过 Visual Studio 命令提示符; 它为您设置所有必需的环境变量。 SDK 中也提供了此命令设置。
Just use MSBuild passing in the solution or project file.
The best way to use MSBuild is via the Visual Studio Command Prompt; it sets all the required environment variables for you. This command setup is also available in the SDK.