问题
Is there a way to compile a .vbproj or .csproj project file directly, just like Visual Studio does?
When you compile in Visual Studio, the "output" window shows the actual call to the compiler, which normally looks like:
vbc.exe [bunch of options] [looooong list of .vb files]
I would like to programatically call "something" that would take the .vbproj file and do whatever Visual Studio does to generate this long command line. I know i could parse the .vbproj myself and generate that command line, but I'd rather save myself all the reverse engineering and trial-and-error...
Is there a tool to do this? I'd rather be able to do it in a machine without having Visual Studio installed. However, if there's a way to call Visual Studio with some parameters to do it, then that'll be fine too.
I looked briefly at MSBuild, and it looks like it works from a .proj project file that i'd have to make especially, and that I'd need to update every time I add a file to the .vbproj file. (I did look briefly at it, so it's very likely I missed something important)
Any help will be greatly appreciated
回答1:
MSBuild is the easiest way to go. For instance:
msbuild /property:Configuration=Release MyFile.vbproj
回答2:
MSBuild can also take your solution file and use it to do the compile.
回答3:
You can use either MSBUILD or CSC. MSBuild, which as you mentioned, does use your project and solution files. CSC will compile specific files, or all files in a specific directory tree.
You should also look at automating your builds with NAnt and/or CruiseControl.net.
Also, here is an example on how to compile your code without visual studio using CSC. http://blog.slickedit.com/?p=163
回答4:
Just so you know .vbproj and .csproj files are MSBuild. So everything that you've read, you can apply to those files directly.
Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build
回答5:
In project solution folder:
msbuild wpfapp1.sln /p:BuildProjectReferences=true
MSbuild is usually located in:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
(or something similar, depending on the version)
csc.exe compiles files, msbuild compiles projects and solutions
回答6:
At the top of a .vbproj file is a . Add this line to the property group to suppress the VB runtime:
<NoVBRuntimeReference>On</NoVBRuntimeReference>
MSBuild does the rest. No need to use the command line if you have the IDE.
来源:https://stackoverflow.com/questions/266308/compiling-a-vbproj-or-csproj-project-file-without-visual-studio