I've made a custom ITaskItem now that adds the files before the build process.
Here's how I've done it:
1) Create custom ITaskItem
public class AddSourceFiles : Task
{
private ITaskItem[] output = null;
[Output]
public ITaskItem[] Output
{
get
{
return output;
}
}
public override bool Execute()
{
//gather a list of files to add:
List<string> filepaths = new List<string>() { "a.cs", "b.cs", "d.cs" };
//convert the list to a itaskitem array and set it as output
output = new ITaskItem[filepaths.Count];
int pos = 0;
foreach (string filepath in filepaths)
{
output[pos++] = new TaskItem(filepath);
}
}
}
2) Create a *.targets file, for example "AddSourceFiles.targets":
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="AddSourceFiles.dll" TaskName="AddSourceFiles" />
<PropertyGroup>
<BuildDependsOn>
AddSourceFiles;
$(BuildDependsOn);
</BuildDependsOn>
</PropertyGroup>
<Target Name="AddSourceFiles">
<AddSourceFiles>
<Output TaskParameter="Output" ItemName="Compile" />
</AddSourceFiles>
</Target>
</Project>
As you can see, the resulting DLL of the class "AddSourceFiles" is referenced in the task file.
3) The last step is to import this .targets file into every .csproj file that you want to include files using your AddSourceFiles class.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
.
.
<Import Project="c:\path\to\AddSourceFiles.targets" />
.
.
</Project>
I'm also very new to this, so feel free to improve this one ;)