NUnit run failing in MSBuild after Upgrade - System.IO.FileLoadException: Could not load file or assembly nunit.framework

StackOverflow https://stackoverflow.com/questions/23141159

  •  05-07-2023
  •  | 
  •  

سؤال

I recently upgraded my solution to Visual Studio 2013 and updated the references to NUnit 2.6.3 in the test libraries from 2.6.2. Everything works fine in Visual Studio but my MSBuild scripts that drive the deployment system are completely borked.

The Build files are in a build directory which contains an MSBuild folder with MSBuild.Community.Targets files which are referenced and an NUnit directory containing nunit-console.exe and various dependent files. I upgraded these to 2.6.3 also.

I just get this error...

' System.IO.FileLoadException: Could not load file or assembly 'nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) '

I don't get this at all - This worked fine before and all the code was referencing 2.6.2 so I have no idea where 2.6.0 is coming from or how on earth I tell it to look for 2.6.3 (which is right there!!)

Here's my build file (if it helps any)...

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DeployAndPackage" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- IMPORTS -->
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildProjectDirectory)\MSBuild\MSBuild.Community.Tasks.targets" />
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
  <!-- PROPERTIES -->
  <PropertyGroup Label="BuildOptions">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">Any CPU</Platform>
    <OutputPath Condition=" '$(OutputPath)' == '' ">bin\</OutputPath>
    <ProjectConfiguration Condition=" '$(Configuration)' == '' ">Debug</ProjectConfiguration>
    <ProjectConfiguration Condition=" '$(Configuration)' == 'Test' ">Debug</ProjectConfiguration>
    <ProjectConfiguration Condition=" '$(Configuration)' == 'Staging' ">Release</ProjectConfiguration>
    <ProjectConfiguration Condition=" '$(Configuration)' == 'Live' ">Release</ProjectConfiguration>
  </PropertyGroup>
  <PropertyGroup Label="DirectoryPaths">
    <RootDir>$(MSBuildProjectDirectory)\..\</RootDir>
    <TestsDir>$(RootDir)Tests\</TestsDir>
    <DatabaseDir>$(RootDir)SiansPlan.Database\</DatabaseDir>
    <RelativePackageDir>$(RootDir)pkg\</RelativePackageDir>
    <Solution>$(RootDir)SiansPlan.sln</Solution>
    <SP_Auth>$(RootDir)SiansPlan.Authentication\SiansPlan.Authentication.csproj</SP_Auth>
    <SP_Database>$(DatabaseDir)SiansPlan.Database.sqlproj</SP_Database>
    <SP_Entities>$(RootDir)SiansPlan.Entities\SiansPlan.Entities.csproj</SP_Entities>
    <SP_Domain>$(RootDir)SiansPlan.Domain\SiansPlan.Domain.csproj</SP_Domain>
    <SP_Providers>$(RootDir)SiansPlan.Providers\SiansPlan.Providers.csproj</SP_Providers>
    <SP_ApiDir>$(RootDir)SiansPlan.Api\</SP_ApiDir>
    <SP_Api>$(SP_ApiDir)SiansPlan.Api.csproj</SP_Api>
    <SP_Web>$(RootDir)SiansPlan.Web\SiansPlan.Web.csproj</SP_Web>
    <SP_SpaDir>$(RootDir)SiansPlan.Spa\</SP_SpaDir>
    <SP_Spa>$(SP_SpaDir)SiansPlan.Spa.csproj</SP_Spa>
    <SP_Test_Support>$(TestsDir)SiansPlan.TestSupport\SiansPlan.TestSupport.csproj</SP_Test_Support>
    <SP_Entities_Tests>$(TestsDir)SiansPlan.Entities.Tests\SiansPlan.Entities.Tests.csproj</SP_Entities_Tests>
    <SP_Auth_Tests>$(TestsDir)SiansPlan.Authentication.Tests\SiansPlan.Authentication.Tests.csproj</SP_Auth_Tests>
    <SP_Domain_Tests>$(TestsDir)SiansPlan.Domain.Tests\SiansPlan.Domain.Tests.csproj</SP_Domain_Tests>
    <SP_Api_Tests>$(TestsDir)SiansPlan.Api.Tests\SiansPlan.Api.Tests.csproj</SP_Api_Tests>
  </PropertyGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>2ae13924-f2dd-48b1-9acb-755e0ee2b0d1</ProjectGuid>
  </PropertyGroup>
  <!-- BUILD -->
  <Target Name="Compile">
    <MSBuild Projects="$(SP_Auth)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Database)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Entities)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Domain)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Providers)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Api)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Web)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Spa)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Test_Support)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Entities_Tests)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Auth_Tests)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Domain_Tests)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
    <MSBuild Projects="$(SP_Api_Tests)" Targets="Rebuild" Properties="Configuration=$(ProjectConfiguration);Platform=$(Platform);OutputPath=bin\" />
  </Target>
  <!-- TEST -->
  <Target Name="RunTests" DependsOnTargets="Compile">
    <CreateItem Include="$(RootDir)Tests\*.Tests\bin\*.Tests.dll">
      <Output TaskParameter="Include" ItemName="TestAssemblies" />
    </CreateItem>
    <NUnit Assemblies="@(TestAssemblies)" ToolPath="$(MSBuildProjectDirectory)\NUnit" DisableShadowCopy="true" />
  </Target>
  <!-- TRANSFORM -->
  <Target Name="Transform">
    <TransformXml Source="$(SP_ApiDir)\Web.config"
                  Transform="$(SP_ApiDir)\Web.$(Configuration).config"
                  Destination="$(SP_ApiDir)\Web.transformed.config"
                  StackTrace="False" />
    <TransformXml Source="$(SP_SpaDir)\Web.config"
                  Transform="$(SP_SpaDir)\Web.$(Configuration).config"
                  Destination="$(SP_SpaDir)\Web.transformed.config"
                  StackTrace="False" />
  </Target>
  <!-- DEPLOY & PACKAGE -->
  <Target Name="DeployAndPackage" DependsOnTargets="RunTests">
    <CallTarget Targets="Transform"/>
    <ItemGroup>
      <SqlFiles Include="$(DatabaseDir)Upgrades\*.sql" />
    </ItemGroup>
    <RemoveDir Directories="$(RelativePackageDir)" />
    <MakeDir Directories="$(RelativePackageDir)" />
    <MakeDir Directories="$(RelativePackageDir)sql\" />
    <Copy SourceFiles="@(SqlFiles)" DestinationFolder="$(RootDir)pkg\sql" />
  </Target>
</Project>

The full output of the 'RunTests' part of the build is...

RunTests:

C:\Development\Clients\SiansPlan\source\build\NUnit\nunit-console.exe /nologo /noshadow C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Api.Tests\bin\SiansPlan.Api.Tests.dll C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Api.Tests\bin\SiansPlan.Domain.Tests.dll C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Authentication.Tests\bin\SiansPlan.Authentication.Tests.dll C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Domain.Tests\bin\SiansPlan.Domain.Tests.dll C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Entities.Tests\bin\SiansPlan.Entities.Tests.dll C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Logging.Tests\bin\SiansPlan.Domain.Tests.dll C:\Development\Clients\SiansPlan\source\build..\Tests\SiansPlan.Logging.Tests\bin\SiansPlan.Logging.Tests.dll ProcessModel: Default DomainUsage: Multiple Execution Runtime: net-4.5 Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77'

Any ideas would be most welcome as I'm at head banging against desk stage. I've asked my desk bear, my rubber duck and Soundwave and none of them have been much use, frankly!

هل كانت مفيدة؟

المحلول

Obscure answer for an obscure problem - It seems I had an old library that was hanging around (Domain.Tests in Logging was a bit of a giveaway) which was causing it to fall over.

cleanfail

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top