I setup a build task following a tutorial several months, which allowed for single named parameters.
However, I'd like to upgrade the task to include multiple parameters. I'm having some difficulty.
Here's my current target file...
<Project>
<PropertyGroup>
<ThisAssembly>$(MSBuildThisFileDirectory)bin\Debug\netstandard2.0\ourapp.build.dll
</ThisAssembly>
<FirstRun>false</FirstRun>
<FirstRun Condition="!Exists('$(ConstantGeneratorOutputFile)')">true</FirstRun>
</PropertyGroup>
<UsingTask TaskName="ourapp.ConstantGeneratorTask"
AssemblyFile="$(ThisAssembly)" />
<!-- Pointing 'Outputs' to a non existing file will disable
up-to-date checks and run the task every time, there's probably a better way -->
<Target Name="ourapp"
BeforeTargets="BeforeCompile;CoreCompile"
Inputs="@(ConstantGeneratorSourceFiles)"
Outputs="$(ConstantGeneratorOutputFile).nocache">
<ConstantGeneratorTask
SourceFiles="@(ConstantGeneratorSourceFiles)"
OutputFile="$(ConstantGeneratorOutputFile)"
AppXamlFile="$(ConstantGeneratorAppXamlFile)"
NameSpaceName="$(ConstantGeneratorNameSpaceName)"/>
<ItemGroup Condition="Exists('$(ConstantGeneratorOutputFile)')">
<FileWrites Include="$(ConstantGeneratorOutputFile)" />
<Compile Include="$(ConstantGeneratorOutputFile)"
Condition="$(FirstRun) == 'true'" />
</ItemGroup>
</Target>
</Project>
And here's the code to read those parameters...
namespace ourapp
{
public class ConstantGeneratorTask : Task
{
[Required]
public string OutputFile { get; set; } = "";
[Required]
public ITaskItem[] SourceFiles { get; set; } = Array.Empty<ITaskItem>();
[Required]
public string NameSpaceName { get; set; } = "";
[Required]
public string AppXamlFile { get; set; } = "";
And heres the csproj parameters
<ConstantGeneratorOutputFile>$(MSBuildThisFileDirectory)/Common/Constants.cs
</ConstantGeneratorOutputFile>
<ConstantGeneratorAppXamlFile>$(MSBuildThisFileDirectory)/App.xaml
</ConstantGeneratorAppXamlFile>
<ConstantGeneratorNameSpaceName>ourapp.Common
</ConstantGeneratorNameSpaceName>
I'd like to provide something like this..
<Items>
<Item XamlFile="$(MSBuildThisFileDirectory)/App.xaml"
NS="ourapp.Common"
OutputFile="$(MSBuildThisFileDirectory)/Common/Constants.cs" />
<Item XamlFile="$(MSBuildThisFileDirectory)/Resources/AutomationIds.xaml"
NS="ourapp.Resources"
OutputFile="$(MSBuildThisFileDirectory)/Common/AutomationIds.cs" />
</Items>
Can anyone point me in the right direction ?