简体   繁体   English

使用MSBuild构建.csproj而不使用项目引用

[英]Build .csproj with MSBuild without project reference

When writing an MSBuild file from scratch, is it possible to build .csproj files directly without a reference to the solution they're a member of? 从头开始编写MSBuild文件时,是否可以直接构建.csproj文件而无需引用他们所属的解决方案? Introductory guides like this one often explain how to compile individual .cs files or build a .csproj directly from the command line. 这样的介绍性指南经常解释如何编译单个.cs文件或直接从命令行构建.csproj。

For example, command line MSBuild without a .sln reference: 例如,没有.sln引用的命令行MSBuild:

msbuild helloworld.csproj /t:Build /verbosity:detailed

Or a .csproj given a .sln: 或.csproj给出.sln:

<MSBuild
  Projects="mysolution.sln"
  Targets="My_Project_File"
  Properties="Configuration=$(Configuration);Platform=$(Platform)"
  ContinueOnError="false" />

I haven't found any references mentioning building the .csproj within an MSBuild file without a .sln. 我没有找到任何提及在没有.sln的MSBuild文件中构建.csproj的引用。 Is there a way and I'm just missing something? 有没有办法,我只是缺少一些东西?

There is nothing wrong whatsoever with building csproj files without a solution: 没有解决方案构建csproj文件没有任何错误:

<MSBuild Projects="my_project.csproj" Targets="Build" />

moreover, when you build a solution with Visual Studio what it actually does internally is convert the solution file to an msbuild script that contains a line like the above to build the projects. 此外,当您使用Visual Studio构建解决方案时,它在内部实际执行的操作是将解决方案文件转换为包含如上所述的行的msbuild脚本来构建项目。

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

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