Since I needed its capability, I forked a NuGet package that was supposed to be able to enable me to process regular expressions in my build, the goal of which is to transform the .NET Framework version number into an environment variable, so that, for example, 4.7 becomes NET47. I am more than sufficiently familiar with regular expressions to make that happen, and the task runs perfectly when I call the assembly from a console program. It finds and loads the assembly, runs its Execute method, and sets the expected property values. However, when I try to run the task in a build, MSBuild reports as follows.
The "RegularExpressionMatching" task could not be loaded from the assembly RegexMatch.MSBuildTask, Version=1.0.0.7, Culture=neutral, PublicKeyToken=659f28f508fc4cd9, processorArchitecture=MSIL. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. C:\Users\DAVE\Documents\Visual Studio 2013\Projects\WizardWrx_Libs\DLLServices2\ConsoleStreamsLab\ConsoleStreamsLab_4.7\ConsoleStreamsLab_4.7.csproj 81 5 ConsoleStreamsLab_4.7
My UsingTask element is as follows.
<UsingTask TaskName="RegularExpressionMatching"
AssemblyName="RegexMatch.MSBuildTask, Version=1.0.0.7, Culture=neutral, PublicKeyToken=659f28f508fc4cd9, processorArchitecture=MSIL" />
My Target block follows.
<Target Name="SecondMatch" AfterTargets="BeforeBuild">
<Message Text="TargetFrameworkVersion = $(TargetFrameworkVersion)" Importance="high" />
<Message Text="DefineConstants = $(DefineConstants)" Importance="high" />
<RegularExpressionMatching Input="$(DefineConstants)" Pattern="^(.*)(*;NET\d{1,2})(;*.*)*$" >
<Output TaskParameter="IsMatch"
PropertyName="IsMatchJiro" />
<Output TaskParameter="Match"
PropertyName="MatchJiro" />
<Output TaskParameter="Replacement"
PropertyName="ReplacementJiro" />
</RegularExpressionMatching>
The first two messages appear in the build log, exactly as expected, and shown, next.
------ Build started: Project: ConsoleStreamsLab_4.7, Configuration: Debug Any CPU ------
Build started 2017/07/24 15:14:29.
SecondMatch:
TargetFrameworkVersion = v4.7
DefineConstants = DEBUG;TRACE
C:\Users\DAVE\Documents\Visual Studio 2013\Projects\WizardWrx_Libs\DLLServices2\ConsoleStreamsLab\ConsoleStreamsLab_4.7\ConsoleStreamsLab_4.7.csproj(81,5): error MSB4062: The "RegularExpressionMatching" task could not be loaded from the assembly RegexMatch.MSBuildTask, Version=1.0.0.7, Culture=neutral, PublicKeyToken=659f28f508fc4cd9, processorArchitecture=MSIL. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Build FAILED.
Time Elapsed 00:00:00.00
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
Diagnostic Level Build Log is a previous attempt, run with the logging level set to Diagnostic. Though it gives a great deal more information, none of it sheds any light on the matter, so far as I can tell.
The assembly in question has a strong name, is installed into the GAC on the machine on which the build ran, and has no unusual dependencies, other than the three MSBuild assemblies.
I suspect the solution might be in the assembly references listed in the RegExMatch Solution, specifically Microsoft.Build.Utilities.v4.0, since I am unsure how that correlates with the build engine that runs in Visual Studio 2013, which reports itself as version 12 (although that may refer only to the version of Visual Studio with which it ships).
I would really like to get this working, so that I can do this task the data driven way, and eliminate hard coded settings. Once I have a proof of concept, I'll be delighted as well to submit a pull request to the original author.
I'll have my eyes open for good suggestions.