错误MSB4057用于名为

时间:2018-01-10 17:43:24

标签: msbuild

我有一个用于在解决方案上调用msbuild的UI,我希望能够检查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了解我发送的内容?

1 个答案:

答案 0 :(得分: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]:

相关问题