1

将 Newtonsoft.Json 升级到 9.0.0 版本并将 ReactJS.Net 包升级到 2.5.0 后,TransformBabel.proj 停止工作:

  <?xml version="1.0" encoding="utf-8" ?>
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformBabel">
      <!-- ReactJS.NET - Transpile JavaScript via Babel -->
      <UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformBabel" />
      <Target Name="TransformBabel">
          <TransformBabel SourceDir="$(MSBuildProjectDirectory)" />
      </Target>
  </Project>

返回以下内容:

TransformBabel.proj(6, 3): error MSB4018: The "TransformBabel" task failed unexpectedly.
[Exec] TransformBabel.proj(6, 3): error MSB4018: React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.IReactSiteConfiguration ---> System.TypeInitializationException: The type initializer for 'React.ReactSiteConfiguration' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

似乎无法加载 Newtonsoft 6.0.0.0 版本。web.config 有一个程序集重定向:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>

但我不确定,因为它正在启动一个新的 msbuild 进程,如果它被忽略。我想提示 msbuild 程序集的位置,但直到现在还没有成功。

4

2 回答 2

1

在这里聚会有点晚了,但希望我的经验能帮助其他有同样问题的人。

我最近遇到了同样的问题,React.MSBuild 3.1.0.它似乎已经硬编码了一个特定的版本,因为我已经Newtonsoft.Json使用 NuGet 将我的更新到最新的(10.0.3)并正确设置了重定向,但是构建仍然因为你提到的相同错误而失败.

我所做的只是卸载所有 React 包(MSBuild 和 Core)以及Newtonsoft.Json(使用-force,因为还有其他依赖项),然后让 NuGetReact.MSBuild再次安装。它已经安装了所有依赖项,导致获得Newtonsoft.Json 9.0.1.

不确定他们为什么将Newtonsoft.Json库限制为特定版本,但这对于 React 开发人员来说更多是一个问题。除非您需要最新的(或其他特定版本),否则这应该可以解决问题。

于 2017-07-04T00:45:40.987 回答
0

我知道这是一篇旧帖子......但这是我的解决方法:

我放入Newtonsoft.Json.dll v6.0.0.0Tools对于项目目录的目录并让msbuild将其复制到$(OutputPath)以满足TransformBabel任务条件。
我的TransformBabel.proj样子是这样的:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformBabel">
  <!-- ReactJS.NET - Transpile JavaScript via Babel -->
  <UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformBabel" />
  <Target Name="TransformBabel">
    <Copy SourceFiles="$(MSBuildProjectDirectory)\Tools\Newtonsoft.Json.dll" DestinationFolder="$(OutputPath)" />
    <TransformBabel SourceDir="$(MSBuildProjectDirectory)" />
  </Target>
</Project>

完成此TransformBabel任务后,让 msbuild用我的项目实际使用的任何版本覆盖Newtonsoft.Json.dll v6.0.0.0,例如: . 所以,在主项目中,我有这样的事情:$(OutputPath)Newtonsoft.Json.dllv8.0.3
.csproj

<ItemGroup>
  ...
  <Reference Include="React.MSBuild, Version=2.3.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78, processorArchitecture=MSIL">
    <HintPath>Tools\React.MSBuild.dll</HintPath>
    <Private>True</Private>
  </Reference>
  ...
</ItemGroup>
...
<ItemGroup>
  ...
  <Content Include="Tools\Newtonsoft.Json.dll" />
  <Content Include="Tools\React.MSBuild.dll" />
  ...
</ItemGroup>
...
<Target Name="TransformBabel" AfterTargets="Build">
  <Exec Command="&quot;$(msbuildtoolspath)\msbuild.exe&quot; $(ProjectDirectory)TransformBabel.proj /p:OutputPath=$(OutputPath) /nr:false" />
</Target>

<Target Name="AfterTransformBabel" AfterTargets="TransformBabel">
  <Copy SourceFiles="..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll" DestinationFolder="$(OutputPath)" />
</Target>

根据您的需要替换任务Newtonsoft.Json.8.0.3内部的路径。AfterTransformBabel

于 2018-01-25T07:04:44.087 回答