自定义共同目标以构建解决方案

问题描述:

我创建了一个自定义的通用目标"RealClean",该目标除去了输出和中间输出"目录中的每个文件.我将其放在Microsoft.Common.targets文件中. 当我在csproj上运行MsBuild时,一切都很好. 但是,当我在sln(仅引用csproj列表)上运行MsBuild时,出现以下错误

I created a custom common target "RealClean" which remove every files in the output and "intermediate output" directory. I put it in the Microsoft.Common.targets file. When I run MsBuild on my csproj everything is fine. But when I run MsBuild on my sln (which just references a list of csproj) I have the following error

error MSB4057: The target "RealClean" does not exist in the project.

这是我输入的用于运行MsBuild的命令行

Here is the command line I enter to run MsBuild

C:\Windows\Microsoft .NET\Framework\v3.5\MsBuild.exe /p:Configuration="Release";OutputPath="..\..\MSBuild.Referentiel.net35";nowarn="1591,1573" /t:RealClean mySolution.sln

有任何提示吗?

要处理解决方案文件,MSBuild将创建一个临时MSBuild项目文件,其中仅包含某些目标,例如 Build Clean 强>.因此,您无法在解决方案文件上调用自定义目标.

To work on solution file, MSBuild creates a temporary MSBuild project file containing only some targets like Build and Clean. So you can't call your custom target on a solution file.