从命令行编译C#.Net [英] Compiling C# .Net from Command Line

查看:367
本文介绍了从命令行编译C#.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图仅使用命令行来编译c#.net项目,以便可以创建一个bat文件来编译和运行Selenium测试.我从SVN导出了代码.我打开了命令提示符,并能够使用以下命令还原软件包.

I'm trying to compile a c# .net project only using command line so that I could create a bat file to compile and run the Selenium tests. I exported the code from SVN. And I opened the command prompt and am able to restore packages using below command.

然后,当我尝试使用msbuild进行编译时,它无法引用通过nuget添加的dll.我知道在Visual Studio中,通过程序包管理器控制台,我可以使用命令(更新-reinstall)并使它正常工作,但是如何在不使用Visual Studio的情况下做到这一点.

And then when I try to compile with msbuild it could not reference the dll added in through the nuget. I know in visual studio through package manager console I can use a command (update -reinstall) and make it work, but how to do this without visual studio.

==== bat file ======
REM Restore External Pacakages
nuget restore packages.config -PacakgesDirectory D:\Testproject\packages"
msbuid TestProject.sln

推荐答案

基本上,您需要引用 Msbuild 可执行文件

Basically you need to reference Msbuild executable

C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe

OR

C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe

然后您需要传递.sln.csproj文件路径(取决于您的工作文件夹)作为参数.

then you need to pass the .sln or .csproj file path (depends on your working folder) as parameter.

您还可以指定msbuild的目标ex. 清洁重建构建 => Visual Studio中存在它们.

You can also specify the msbuild's targets ex. Clean, Rebuild, Build => As they exists in Visual Studio.

最终命令如下所示:

模板:

{.NetFrameworkPath}\msbuild.exe {pathToSln} /t:{Build,Clean,Rebuild}

示例

C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe TestProject.sln /t:Build

C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe TestProject.sln /t:Clean;Build 

这篇关于从命令行编译C#.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆