I have a custom msbuild task with an output parameter defined below
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
}
In my build script(csproj file) I extend msbuild by injecting my custom task in the AfterBuild target as defined below
<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"/>
However, msbuild complains “Unknown output parameter Result,’DeployJavaScript’ should have no output parameters”
Why I cannot return an output parameter in this scenario?
P.S
I know I can use Log.LogMessage(MessageImportance.high,”sucess”,high) to log the result in the proj file which would serve my purpose. Just want to know why I cannot use an output parameter.
You have to change the type of the
Resultproperty in your code. UseITaskIteminstead ofstring. For me it helped to solve the same problem.Naturally, your code will have to create an instance of
TaskItemclass after that:Result = new TaskItem(String.Format("Sucessfully Deployed Javascript Files"));