简体   繁体   English

如何从命令行构建.csproj,并将日志写入指定位置?

[英]How does one build a .csproj from command line having a log written to a specified location?

While the 'no-log' build seems to work smoothly with something like 虽然“无日志”构建似乎可以与类似

"c:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\ide\\VCSExpress" Project1.csproj /build “ c:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ Common7 \\ ide \\ VCSExpress” Project1.csproj / build

the following fails: 以下失败:

"c:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\ide\\VCSExpress" Project1.csproj /build /Log=log.txt “ c:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ Common7 \\ ide \\ VCSExpress” Project1.csproj / build /Log=log.txt

showing a window with this text: 显示带有此文本的窗口:

Missing switch argument. 缺少开关参数。 Configuration name required for /build switch. / build开关所需的配置名称。

Use: vcsexpress [solutionfile | 使用:vcsexpress [solutionfile | projectfile | 工程文件| anyfile.ext] [switches] anyfile.ext] [开关]

The first argument for vcsexpress is usually a solution file or project file. vcsexpress的第一个参数通常是解决方案文件或项目文件。 You can also use any other file as the first argument if you want to have the file open automatically in an editor. 如果要在编辑器中自动打开文件,也可以将其他任何文件用作第一个参数。 When you enter a project file, the IDE looks for an .sln file with the same base name as the project file in the parent directory for the project file. 输入项目文件时,IDE会在项目文件的父目录中查找与该项目文件具有相同基本名称的.sln文件。 If no such .sln file exists, then the IDE looks for a single .sln file that references the project. 如果不存在这样的.sln文件,则IDE将查找引用该项目的单个.sln文件。 If no such single .sln file exists, then the IDE creates an unsaved solution with a default .sln file name that has the same base name as the project file. 如果不存在这样的单个.sln文件,则IDE将使用默认.sln文件名创建未保存的解决方案,该默认.sln文件名与项目文件具有相同的基本名称。

Command line builds: vcsexpress solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ] Available command line switches: 命令行构建:vcsexpress solutionfile.sln / build [solutionconfig] [/ project projectnameorfile [/ projectconfig name]]可用的命令行开关:

/Log Logs IDE activity to the specified file for troubleshooting. / Log将IDE活动记录到指定的文件中以进行故障排除。 /ResetSettings Restores the IDE's default settings, optionally resets to the specified VSSettings file. / ResetSettings恢复IDE的默认设置,还可以选择重置为指定的VSSettings文件。 /SafeMode Launches the IDE in safe mode loading minimal windows. / SafeMode以安全模式启动IDE,并加载最少的窗口。

Product-specific switches: 产品专用开关:

To attach the debugger from the command line, use: VsJITDebugger.exe -p 要从命令行附加调试器,请使用:VsJITDebugger.exe -p

[I am using Visual Studio 2008 Express] [我正在使用Visual Studio 2008 Express]

So, the questions are: 因此,问题是:

  • Is there a way to ensure that the log file is written somewhere? 有没有办法确保将日志文件写入某处?

  • Or is the /Log switch only supposed to be used when the IDE is run in GUI mode? 还是仅在以GUI模式运行IDE时才应使用/Log开关? If so, are there workarounds? 如果是这样,是否有解决方法?

Under the hood, Visual Studio uses msbuild for all it's build magic. 在后台,Visual Studio使用msbuild进行所有构建。 As far as I know, this applies to the Express editions as well. 据我所知,这也适用于Express版本。

If you don't have it already, MSBuild is a part of the .NET SDK. 如果尚未安装,则MSBuild是.NET SDK的一部分。

Calling MSBuild has the advantage of doing the build directly - calling VCSExpress will just introduce overhead. 调用MSBuild具有直接进行构建的优势-调用VCSExpress只会带来开销。

Here's the MSBuild commandline that I've used: 这是我使用过的MSBuild命令行:

msbuild.exe <solution> 
    /t:rebuild 
    /verbosity:quiet 
    /logger:FileLogger,Microsoft.Build.Engine;logfile=<filePath>

Should work the same with <project> instead of <solution> . 应该与<project>而不是<solution>

You have to specify the configuration after the /build option. 您必须在/ build选项之后指定配置。 Also, the log file must already exist, it doesn't create one from scratch. 此外,日志文件必须已经存在,它不会从头开始创建一个。 Thus: 从而:

copy con > log.txt
^Z      // Type Ctrl+Z
"c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\VCSExpress" Project1.csproj /build debug /log log.txt

In the window that pops up with all the info.. it gives you the error: 在弹出所有信息的窗口中。它给您错误:

Missing switch argument. 缺少开关参数。 Configuration name required for /build switch. / build开关所需的配置名称。

And then it gives you a bunch of info including this: 然后,它为您提供了一堆信息,其中包括:

Command line builds: vcsexpress solutionfile.sln /build [ solutionconfig ] 命令行构建: vcsexpress solutionfile.sln /build [ solutionconfig ]

It just wants to know what kind of solution config you have - I think either "Release" or "Debug". 它只是想知道您具有哪种解决方案配置-我认为是“发布”或“调试”。 Not sure if vcsexpress has the "Configuration Manager" or Solution Build Property Pages under the "Build" Menu.. but this would be where you could double check your current settings. 不知道vcsexpress是否在“构建”菜单下具有“配置管理器”或“解决方案构建属性页”。但这是您可以再次检查当前设置的位置。 See the "Active Solution Configuration".. this person ran into this, check out their screen shot of it: MSBuild task configuration property 请参阅“活动解决方案配置”。该人员遇到了此问题,请查看其屏幕截图: MSBuild任务配置属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM