无法从程序集RegexMatch.MSBuildTask

时间:2017-07-24 21:14:21

标签: c# visual-studio-2013 msbuild-task msbuild-4.0

由于我需要它的功能,我分叉了一个NuGet包,它应该能够让我在我的构建中处理正则表达式,其目标是将.NET Framework版本号转换为环境变量,所以例如,4.7成为NET47。我非常熟悉正则表达式以实现这一点,当我从控制台程序调用程序集时,任务运行完美。它查找并加载程序集,运行其Execute方法,并设置预期的属性值。但是,当我尝试在构建中运行任务时,MSBuild会报告如下。

无法从程序集R egexMatch.MSBuildTask,Version = 1.0.0.7,Culture = neutral,PublicKeyToken = 659f28f508fc4cd9,processorArchitecture = MSIL RegularExpressionMatching ”任务>。确认声明是否正确,程序集及其所有依赖项是否可用,以及该任务是否包含实现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

我的UsingTask元素如下。

  <UsingTask TaskName="RegularExpressionMatching"
             AssemblyName="RegexMatch.MSBuildTask, Version=1.0.0.7, Culture=neutral, PublicKeyToken=659f28f508fc4cd9, processorArchitecture=MSIL" />

我的目标块如下。

  <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>

前两条消息显示在构建日志中,完全符合预期,并显示在下一页。

------ 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是先前的尝试,在日志记录级别设置为Diagnostic的情况下运行。虽然它提供了更多的信息,但据我所知,这些信息都没有说明这个问题。

有问题的程序集有一个强名称,安装在运行构建的机器上的 GAC 中,并且没有异常的依赖关系,除了三个 MSBuild 程序集。

我怀疑解决方案可能位于RegExMatch Solution中列出的程序集引用中,特别是 Microsoft.Build.Utilities.v4.0 ,因为我不确定它与构建的关系如何在Visual Studio 2013中运行的引擎,它将自身报告为版本12(尽管这可能仅指它所附带的Visual Studio版本)。

我真的很想让这个工作,所以我可以用数据驱动的方式完成这项任务,并消除硬编码设置。一旦我有了概念证明,我也很高兴向原作者提交拉取请求。

我会睁着眼睛看好建议。

1 个答案:

答案 0 :(得分:0)

您是否导入了扩展程序的项目?我没有使用你使用的特定扩展,但是当我使用MSBuildExtensions时,我必须添加一组行来影响:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

只有在此行出现后,才能访问目标并使用扩展名。

相关问题