Compiling C# .Net from Command Line

帅比萌擦擦* 提交于 2019-12-13 09:10:18

问题


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.

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

回答1:


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

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

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

The final command could look like this:

Template:

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

Examples

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 


来源:https://stackoverflow.com/questions/36093175/compiling-c-sharp-net-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!