vb.net 在没有 Visual Studio 的情况下编译 .vbproj 或 .csproj 项目文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/266308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:53:51  来源:igfitidea点击:

Compiling a .vbproj or .csproj project file without Visual Studio

visual-studiocompilationcsprojvb.net

提问by Daniel Magliola

Is there a way to compile a .vbproj or .csproj project file directly, just like Visual Studio does?

有没有办法像 Visual Studio 一样直接编译 .vbproj 或 .csproj 项目文件?

When you compile in Visual Studio, the "output" window shows the actual call to the compiler, which normally looks like:

在 Visual Studio 中编译时,“输出”窗口显示对编译器的实际调用,通常如下所示:

vbc.exe [bunch of options] [looooong list of .vb files]

vbc.exe [一堆选项] [looooong .vb 文件列表]

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 couldparse the .vbproj myself and generate that command line, but I'd rather save myself all the reverse engineering and trial-and-error...

我想以编程方式调用“某物”,它会使用 .vbproj 文件并执行 Visual Studio 所做的任何操作来生成这个长命令行。我知道我可以自己解析 .vbproj 并生成该命令行,但我宁愿省去所有的逆向工程和反复试验...

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.

有没有工具可以做到这一点?我宁愿能够在没有安装 Visual Studio 的机器上完成它。但是,如果有一种方法可以使用一些参数调用 Visual Studio 来执行此操作,那也没关系。

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 brieflyat it, so it's very likely I missed something important)

我简要地查看了 MSBuild,它看起来像是从我必须特别制作的 .proj 项目文件中工作,并且每次我将文件添加到 .vbproj 文件时我都需要更新。(我做了一下简单的,所以它很可能我错过了一些重要的东西)

Any help will be greatly appreciated

任何帮助将不胜感激

回答by Jon Skeet

MSBuild is the easiest way to go. For instance:

MSBuild 是最简单的方法。例如:

msbuild /property:Configuration=Release MyFile.vbproj

回答by Rob Prouse

MSBuild can also take your solution file and use it to do the compile.

MSBuild 还可以获取您的解决方案文件并使用它进行编译。

回答by AaronS

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.

您可以使用 MSBUILD 或 CSC。正如您所提到的,MSBuild 确实使用您的项目和解决方案文件。CSC 将编译特定文件,或特定目录树中的所有文件。

You should also look at automating your builds with NAnt and/or CruiseControl.net.

您还应该考虑使用 NAnt 和/或 CruiseControl.net 自动化构建。

Also, here is an example on how to compile your code without visual studio using CSC. http://blog.slickedit.com/?p=163

此外,这里有一个示例,说明如何使用 CSC 在没有 Visual Studio 的情况下编译代码。 http://blog.slickedit.com/?p=163

回答by Sayed Ibrahim Hashimi

Just so you know .vbproj and .csproj files are MSBuild. So everything that you've read, you can apply to those files directly.

只是让您知道 .vbproj 和 .csproj 文件是 MSBuild。因此,您阅读的所有内容都可以直接应用于这些文件。

Sayed Ibrahim Hashimi

赛义德·易卜拉欣·哈希米

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

我的书:Microsoft Build Engine 内部:使用 MSBuild 和 Team Foundation Build

回答by Alexander Ivanov

In project solution folder:

在项目解决方案文件夹中:

msbuild wpfapp1.sln /p:BuildProjectReferences=true

MSbuild is usually located in:

MSbuild 通常位于:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

(or something similar, depending on the version)

(或类似的东西,取决于版本)

csc.exe compiles files, msbuild compiles projects and solutions

csc.exe 编译文件,msbuild 编译项目和解决方案

回答by JWPlatt

At the top of a .vbproj file is a . Add this line to the property group to suppress the VB runtime:

.vbproj 文件的顶部是一个 . 将此行添加到属性组以抑制 VB 运行时:

<NoVBRuntimeReference>On</NoVBRuntimeReference>

MSBuild does the rest. No need to use the command line if you have the IDE.

MSBuild 完成剩下的工作。如果您有 IDE,则无需使用命令行。