如何使用 TeamCity 将此公共属性传递给 MSBuild?

发布于 2024-12-26 04:46:15 字数 531 浏览 0 评论 0原文

我正在使用 TeamCity Visual Studio 运行程序。我想添加一个无法从 Visual Studio 访问的设置。

/Property:FileAlignment=4096

我直接将其输入到构建步骤“命令行参数”中。构建日志显示错误:

MSBuild 命令行参数包含“/property:”或“/p:”参数。请改用构建参数。

我不明白如何从 TeamCity 向 MSBuild 提供此信息并消除此警告!

1. 我应该使用哪种参数?

有3种:

  • 配置参数
  • 系统属性
  • 环境变量。

我不需要环境或系统变量,因为我不希望此构建依赖于任何外部内容。我现在要尝试配置,但是我不确定我是否填写正确。

2. 如何判断这个参数是否实际被使用?

构建日志似乎只具有可导航/可折叠的类似 xml 级别的程序,但没有说明构建参数。

I am using the TeamCity Visual Studio runner. I want to add a setting that is not accessible from Visual Studio.

/Property:FileAlignment=4096

I typed that directly into the build step "Command line parameters." The build log shows the error:

MSBuild command line parameters contains "/property:" or "/p:" parameters. Please use Build Parameters instead.

I don't understand how to provide this to MSBuild from TeamCity and get rid of this warning!

1. Which kind of parameter should I use?

There are 3 kinds:

  • Configuration parameters
  • System properties
  • Environment variables.

I don't want an environment or system variable because I don't want this build to depend on anything external. I am going to try Config right now, but then I'm not sure I'm filling it in right.

2. How can I tell this parameter is actually getting used?

The build log, which seems only to have navigable/foldable xml-like levels with their program, did not say the build parameters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

面如桃花 2025-01-02 04:46:15

您应该使用“系统属性”。不用担心名称,TeamCity 就是这么称呼它的。它们是常规属性。您可以在“编辑配置设置> 7.构建参数”中添加它们。

例如,您可以按如下方式添加系统属性:

名称:system.FileAlignment

类型:系统属性(系统)

价值:4096

请注意,TeamCity 将坚持使用“系统”。前缀。这并不重要,因为 MSBuild 脚本仍会将其视为 $(FileAlignment)。

You should use "System properties". Don't worry about the name, that's just how TeamCity calls it. They are regular properties. You can add them in "Edit Configuration Settings > 7. Build Parameters".

For example, you can add the system property as follows:

Name: system.FileAlignment

Type: System property (system.)

Value: 4096

Note that TeamCity will insist on the "system." prefix. It doesn't matter because the MSBuild script will still see it as $(FileAlignment).

浅笑轻吟梦一曲 2025-01-02 04:46:15

TeamCity 文档将构建参数定义为“一种便捷的方式将通用或特定于环境的设置传递到构建脚本中”。配置参数提供了一种覆盖从模板继承的构建配置中的某些设置的方法。 它们永远不会传递到构建。系统和环境参数提供给您的构建脚本。环境变量实际上是在系统上设置的(我找不到这方面的任何文档)。系统参数传递到脚本引擎

TeamCity 自动向实际命令行提供系统变量(看起来 Visual Studio 运行程序运行 msbuild.exe 而不是 devenv.exe)。我猜想 TeamCity 正在构建一个命令,就像

cmd> msbuild.exe my-solution.sln /p:FileAlignment=4096

我在命令行上尝试的那样,只是为了确保它应该工作(我添加了 /v:diagnostic 标志)。诊断的详细程度使 msbuild 将其所有属性打印到控制台。我验证了 FileAlignment=4096 位于其中。

/FileAlignment 属性似乎是一个特殊属性 会自动出现在任何 .csproj 文件中。所以你应该可以走了。您可以通过单击任何构建并查看“构建参数”选项卡来检查传递给构建的实际参数。有一个部分显示“代理的实际参数”。

The TeamCity documentation defines Build Parameters as "a convenient way of passing generic or environment-specific settings into the build script". Configuration parameters provide a way to override some settings in a build configuration inherited from a template. They are never passed to a build. System and Environment parameters are provided to your build script. Environment variables are actually set on the system (I can't find any documentation for this). System parameters are passed to the script engine.

TeamCity automatically provides System variables to the actual command line (it looks like the Visual Studio runner runs msbuild.exe and not devenv.exe). I guess that TeamCity is constructing a command like

cmd> msbuild.exe my-solution.sln /p:FileAlignment=4096

I tried this on my command line, just to make sure that it should work (I added the /v:diagnostic flag). The diagnostic verbosity makes msbuild print all of it's properties to the console. I verified that FileAlignment=4096 was in there.

That /FileAlignment property appears to be a special property that's automatically in any .csproj file. So you should be good to go. You can check the actual parameters that were passed to the build by clicking on any build and viewing the 'Build Parameters' tab. There's a section that shows the "Actual Parameters on Agent".

阿楠 2025-01-02 04:46:15

这事就解决了。为了澄清这一点,Anthony 讲述了如何使用 MSBuild 在命令行中解决问题。也可以使用 devenv 在命令行上解决,根据 Microsoft 的票据,语法是:

 devenv ..\..\mysolution.sln /Rebuild /Property:Config=Release;Platform=AnyCPU;Filealignment=512

但是,我想要的是让 Teamcity 的“Visual Studio Build”接受该参数。这是通过如下方式实现的。在“命令行参数”框中,我输入:

/Property:FileAlignment=filealignment v:diag

然后“构建参数”的输出选项卡显示:

User Defined Parameters
Name                    Value passed to build
system.filealignment    512
system.verbosity        diagnostic

This was solved. To clarify, Anthony told how to solve the problem in the commandline using MSBuild. It can also be solved on the commandline using devenv, per a ticket with Microsoft, the syntax is:

 devenv ..\..\mysolution.sln /Rebuild /Property:Config=Release;Platform=AnyCPU;Filealignment=512

What I wanted, however, was to get Teamcity's "Visual Studio Build" to accept the parameter. This was achieved as follows. In the box for Command line parameters, I entered:

/Property:FileAlignment=filealignment v:diag

Then the output tab for Build Parameters shows:

User Defined Parameters
Name                    Value passed to build
system.filealignment    512
system.verbosity        diagnostic
寂寞陪衬 2025-01-02 04:46:15

(评论的长度为 -754 个字符,因此必须作为帖子输入)

嗨,安东尼,谢谢您的回复!
是的,命令行上的 msbuild 对我来说也可以正常工作,并且项目文件可以存储 FileAlignment 属性。在我们的例子中,根据与 Microsoft 的讨论,除了修复项目(我已经完成了)之外,我似乎有必要指定解决方案范围(也称为构建范围)对齐,即在命令参数中。

我在 GUI 项( /Build Step / Command line parameters/ )上指定的任何参数都不会出现在选项卡 /BuildParameters/ 上。当然有些根本无法编译。

另外,我在使用时有更奇怪的行为
/冗长:诊断

/冗长:最小
导致最小的构建日志更长!诊断似乎将细节隐藏在特殊任务中,该任务是 Teamcity 的一部分,而不是我;
[16:24:05]:使用项目“C:\WINDOWS\”中的目标“SatelliteDllsProjectOutputGroup”覆盖项目“C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets”中的目标“SatelliteDllsProjectOutputGroup” Microsoft.NET\Framework\v3.5\Microsoft.WinFX.targets”。
我正在努力解决这个问题,因为 Teamcity 生成的构建输出日志作为 TreeView 非常好。这适用于 SLN 构建,但使用任何 bat 文件都无法生成具有漂亮(大概是 xml)树格式的日志文件。

如果您有更多的想法,我很乐意听到它们,并感谢您的编辑! :)

(This is -754 chars for a comment so must be typed as a post)

hi Anthony, Thank you for replying!
Yes, msbuild on the commandline works fine for me as well and project files may store FileAlignment properties. In our case, upon discussion with Microsoft, it appears necessary that I specify the solution-wide aka build-wide alignment, ie in the command arguments, in addition to fixing the projects (which I have already done).

No parameter that I specify on the GUI item ( /Build Step / Command line parameters/ ) will appear on the tab /Build Parameters/. Of course some will not compile at all.

Also I have even more weird behavior where using
/verbosity:diagnostic
vs
/verbosity:minimal
causes a longer build log for the minimal! It appears diagnostic is hiding the details inside of a special task, which is part of Teamcity and not me;
[16:24:05]: Overriding target "SatelliteDllsProjectOutputGroup" in project "C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets" with target "SatelliteDllsProjectOutputGroup" from project "C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.WinFX.targets".
I am struggling with this because the Teamcity-generated build output log is so nice to have as a TreeView. That works with the SLN build but using any bat file cannot produce log file with the pretty (xml, presumably) tree-format.

If you have further ideas I will love to hear them, and thank you for your edits! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文