无法识别自定义msbuild任务输出
我有一个自定义msbuild任务,其输出参数定义如下无法识别自定义msbuild任务输出,msbuild,extend,msbuild-task,csproj,Msbuild,Extend,Msbuild Task,Csproj,我有一个自定义msbuild任务,其输出参数定义如下 public class DeployJavaScript : Task { [Required] public ITaskItem[] SourceFiles { get; set; } [Output] public string Result { get; set; } #region Overrides of Task public override bool Execute()
public class DeployJavaScript : Task
{
[Required]
public ITaskItem[] SourceFiles { get; set; }
[Output]
public string Result { get; set; }
#region Overrides of Task
public override bool Execute()
{
foreach (var sourceFile in SourceFiles)
{
}
Result = String.Format("Sucessfully Deployed Javascript Files");
return true;
}
#endregion Overrides of Task
}
<Target Name="AfterBuild">
<Message Text="AfterBuild Begin" Importance="high"/>
<PropertyGroup>
<JavaScriptFolderPath Condition=" '$(JavaScriptFolderPath)' == '' " >$(MSBuildProjectDirectory)\</JavaScriptFolderPath>
<JavaScriptFilePath></JavaScriptFilePath>
</PropertyGroup>
<ItemGroup>
<JavaScriptFolderFiles Include="$(JavaScriptFolderPath)\**\*.js"/>
</ItemGroup>
<ItemGroup>
<JavaScriptFiles Include="$(JavaScriptFilePath)"/>
</ItemGroup>
<DeployJavaScript SourceFiles="@(JavaScriptFolderFiles->'%(FullPath)')">
<Output TaskParameter="Result" PropertyName="ResultofJavaScriptDeployment"/>
</DeployJavaScript>
<Message Text="$(ResultofJavaScriptDeployment)" Importance="high"/>
<Message Text="AfterBuild Complete" Importance="high"/>
在我的构建脚本(csproj文件)中,我通过在后构建目标中注入自定义任务来扩展msbuild,如下所述
public class DeployJavaScript : Task
{
[Required]
public ITaskItem[] SourceFiles { get; set; }
[Output]
public string Result { get; set; }
#region Overrides of Task
public override bool Execute()
{
foreach (var sourceFile in SourceFiles)
{
}
Result = String.Format("Sucessfully Deployed Javascript Files");
return true;
}
#endregion Overrides of Task
}
<Target Name="AfterBuild">
<Message Text="AfterBuild Begin" Importance="high"/>
<PropertyGroup>
<JavaScriptFolderPath Condition=" '$(JavaScriptFolderPath)' == '' " >$(MSBuildProjectDirectory)\</JavaScriptFolderPath>
<JavaScriptFilePath></JavaScriptFilePath>
</PropertyGroup>
<ItemGroup>
<JavaScriptFolderFiles Include="$(JavaScriptFolderPath)\**\*.js"/>
</ItemGroup>
<ItemGroup>
<JavaScriptFiles Include="$(JavaScriptFilePath)"/>
</ItemGroup>
<DeployJavaScript SourceFiles="@(JavaScriptFolderFiles->'%(FullPath)')">
<Output TaskParameter="Result" PropertyName="ResultofJavaScriptDeployment"/>
</DeployJavaScript>
<Message Text="$(ResultofJavaScriptDeployment)" Importance="high"/>
<Message Text="AfterBuild Complete" Importance="high"/>
$(MSBuildProjectDirectory)\
但是,msbuild抱怨“输出参数结果未知,'DeployJavaScript'应该没有输出参数”
为什么在这种情况下我不能返回输出参数
附言
我知道我可以使用Log.LogMessage(MessageImportance.high,“success”,high)将结果记录到proj文件中,这将符合我的目的。只想知道为什么我不能使用输出参数。您必须更改代码中的
结果属性的类型。使用ITaskItem
而不是string
。对我来说,这有助于解决同样的问题。
当然,在此之后,您的代码必须创建TaskItem
类的实例:
Result=newtaskItem(String.Format(“成功部署的Javascript文件”)代码>