Could not load file or assembly “System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”

后端 未结 15 1544
滥情空心
滥情空心 2020-11-28 18:31

I\'ve copied my project to a clean Windows 10 machine with only Visual Studio 2015 Community and SQL Server 2016 Express installed. There are no other framework versions ins

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 19:03

    I have same issue and only way how i am able to fix it is add bindingRedirect to app.confing how wrote @tripletdad99.

    But if you have solution with more project is really suck update every project by hand (and also sometimes after update some nuget package you need to do it again). And it is reason why i wrote simple powershell script which if all app.configs.

     param(
        [string]$SourceDirectory,
        [string]$Package,
        [string]$OldVersion,
        [string]$NewVersion
    )
    
    Write-Host "Start fixing app.config in $sourceDirectory"
    Write-Host "$Package set oldVersion to $OldVersion and newVersion $NewVersion"
    Write-Host "Search app.config files.."
    [array]$files = get-childitem $sourceDirectory -Include app.config App.config -Recurse | select -expand FullName
    foreach ($file in $files)
    {
        Write-Host $file
        $xml = [xml](Get-Content $file)
        $daNodes = $xml.configuration.runtime.assemblyBinding.dependentAssembly
        foreach($node in $daNodes)
        {
            if($node.assemblyIdentity.name -eq $package)
            {
                $updateNode = $node.bindingRedirect
                $updateNode.oldVersion = $OldVersion
                $updateNode.newVersion =$NewVersion
                Write-Host "Fix"
            }
        }
        $xml.Save($file)
    }
    
    Write-Host "Done"
    

    Example how to use:

    ./scripts/FixAppConfig.ps1 -SourceDirectory "C:\project-folder" -Package "System.Net.Http" -OldVersion "0.0.0.0-4.3.2.0" -NewVersion "4.0.0.0"
    

    Probably it is not perfect and also it will be better if somebody link it to pre-build task.

提交回复
热议问题