我是一個MSBuild的新手,想玩一下它,但我無法弄清楚爲什麼這不起作用。使用來自同一解決方案的自定義MSBuild任務?
所以我的解決方案有兩個項目:「模型」和「BuildTasks」。 BuildTasks只是有一個類:
using Microsoft.Build.Utilities;
namespace BuildTasks
{
public class Test : Task
{
public override bool Execute()
{
Log.LogMessage("FASDfasdf");
return true;
}
}
}
然後在Model.csproj我添加了這一點:
<UsingTask TaskName="BuildTasks.Test" AssemblyFile="$(SolutionDir)src\BuildTasks\bin\BuildTasks.dll" />
<Target Name="AfterBuild">
<Test />
</Target>
我已經設置了構建順序,以便「BuildTasks」被前「建模型」。但是當我試圖建立模型我得到這個錯誤:
The "BuildTasks.Test" task could not be loaded from the assembly C:\WIP\TestSolution\src\BuildTasks\bin\BuildTasks.dll. Could not load file or assembly 'file:///C:\WIP\TestSolution\src\BuildTasks\bin\BuildTasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available.
這個文件肯定存在,所以爲什麼不能MSBuild找到它?
我甚至試過在「$(SolutionDir)」的地方硬編碼「C:\ WIP \ TestSolution」,並得到相同的錯誤。但是,如果我將該.dll複製到我的桌面並將路徑硬編碼到我的桌面,則工作,我不明白爲什麼。
編輯:我沒有路徑錯誤。我修改了BuildTasks的Debug/Release版本,將.dll輸出到bin文件夾,因爲我不想讓Debug/Release具有不同的路徑。
你是否設法解決這個問題?我有同樣的問題。 – sean 2009-05-03 17:18:12
3年沒有解決?我有這個問題,但這篇文章沒有幫助,因爲它不清楚問題是不是已經解決了...... – DaveN59 2012-04-16 19:34:58