【问题标题】:Error MSB4057 for msbuild targets with period in name名称中带有句点的 msbuild 目标的错误 MSB4057
【发布时间】:2018-06-19 23:09:54
【问题描述】:

我有一个 UI 可以在解决方案上调用 msbuild,并且我希望能够选中 UI 中的一些框以指定要在解决方案中构建哪些项目。我正在使用这样的 msbuild:

msbuild mysolution.sln /t:"proj1" /t:"proj2"

只要项目是字母数字,一切正常。但是当我得到一个名称中有句点的项目时:

msbuild mysolution.sln /t:"ABC.XYZ"

我收到这样的错误(用...跳过一些不相关的细节):

Microsoft (R) Build Engine version 14.0.25420.1
...

Project "C:\...\mysolution.sln" on node 1 (ABC.XYZ target(s))
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU"
C:\...\mysolution.sln.metaproj : error MSB4057: The target "ABC.XYZ" does not exist in the project. [c:\...\mysolution.sln]

显然在这个例子中,项目 ABC.XYZ 确实存在于 mysolution.sln 中。

这只是一个没有解决方法的错误吗?或者这是预期的行为,我需要以某种方式修改名称以便 msbuild 了解我发送的内容?

【问题讨论】:

    标签: msbuild


    【解决方案1】:

    我在方法static private string CleanseProjectName(string projectName)中的msbuild源代码中找到了解决方案:

    https://github.com/Microsoft/msbuild -> ProjectInSolution.cs#L340

    我们可以看到它破坏了目标名称,具体来说,它替换了:

    private static readonly char[] charsToCleanse = { '%', '$', '@', ';', '.', '(', ')', '\'' };
    

    与:

    private const char cleanCharacter = '_';
    

    所以ABC.XYZ这样的目标名称需要编码为ABC_XYZ,否则找不到。

    [2]:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2016-12-23
      • 1970-01-01
      • 2019-11-03
      相关资源
      最近更新 更多