在将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程序集的位置,但直到现在还没有成功。
发布于 2017-07-04 08:45:41
在这里参加聚会有点晚了,但希望我的经验能对其他有同样问题的人有所帮助。
我最近遇到了与React.MSBuild 3.1.0.相同的问题,似乎它已经硬编码了一个特定的版本,因为我已经使用NuGet将我的Newtonsoft.Json更新到了最新的(10.0.3),并正确地设置了重定向,但是构建仍然因为你提到的相同的错误而失败。
我所做的只是卸载所有的React包(MSBuild和核心)以及Newtonsoft.Json (使用-force,因为有其他依赖项),然后让NuGet再次安装React.MSBuild。它已经安装了导致获得Newtonsoft.Json 9.0.1.的所有依赖项
不确定为什么他们将Newtonsoft.Json库限制在特定的版本,但这更多的是React开发人员的问题。除非您需要最新版本(或其他特定版本),否则这应该可以解决问题。
发布于 2018-01-25 15:04:44
我知道这是一个旧的post...but,这是我的解决办法:
我将Newtonsoft.Json.dll v6.0.0.0放到相对于项目目录的Tools目录中,并让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用我的项目实际使用的任何$(OutputPath)版本覆盖Newtonsoft.Json.dll中的v8.0.3,例如:v8.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=""$(msbuildtoolspath)\msbuild.exe" $(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>根据需要替换path Newtonsoft.Json.8.0.3 inside AfterTransformBabel任务。
https://stackoverflow.com/questions/38402521
复制相似问题