Visual Studio 2017 Professional:部分机器引用无法解析问题求助
Hey there, let's work through this reference resolution issue you're hitting. The root of the problem comes from manually overriding the default system assembly references to point to a specific NuGet package path—this hardcoded relative path is prone to breaking across different machine environments. Here's a step-by-step breakdown to fix it:
1. Verify NuGet Package Restoration First
Start with the most common culprit: missing or mismatched packages on affected machines:
- In Visual Studio, right-click your project → Manage NuGet Packages, check that
System.Runtimeversion 4.3.0 is installed - If it's missing, install the exact version; if it exists, right-click the solution → Restore NuGet Packages to ensure all dependencies are pulled down
- Manually check the project's
packagesfolder to confirmSystem.Runtime.4.3.0\lib\net462\System.Runtime.dllexists, and that the relative path in your HintPath (..\..\..\) matches the actual directory structure of the project on the affected machine (some folks might clone the repo to a different folder depth, breaking the relative path)
2. Align the Reference with Your Project's Target Framework
Your project targets .NET Framework 4.7.1, but the HintPath points to the net462 build of the DLL. While 4.7.1 is backward-compatible, it's better to use the closest matching framework build if available:
- Navigate to
System.Runtime.4.3.0\libin your packages folder—if there's anet471subdirectory, update the HintPath to point to that DLL - Double-check your project's target framework setting: right-click project → Properties → Application, confirm it's set to
.NET Framework 4.7.1
3. Add or Update Assembly Binding Redirects
.NET Framework relies on binding redirects to resolve version conflicts for system assemblies. Open your project's Web.config (or App.config) and ensure you have a redirect for System.Runtime:
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>
If this section is missing, add it—make sure the newVersion matches your installed NuGet package version.
4. Consider Reverting to Default Reference (If Possible)
If your original version issue is now resolved via NuGet and binding redirects, you can revert to the default reference format to avoid path-related issues entirely:
<Reference Include="System.Runtime" />
.NET will automatically pull the correct version from either the GAC or your NuGet packages, eliminating the need for hardcoded paths.
5. Resolve GAC Assembly Conflicts
Some machines might have conflicting versions of System.Runtime in the Global Assembly Cache (GAC) that override your HintPath. To check this:
- Open an elevated Command Prompt and run:
gacutil /l System.Runtime - If you see conflicting versions, you can either uninstall the incompatible one (careful—this might affect other projects) or force your project to use the specific NuGet version by adding
SpecificVersion=Trueto your reference:<Reference Include="System.Runtime, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath> <Private>True</Private> <SpecificVersion>True</SpecificVersion> </Reference>
内容的提问来源于stack exchange,提问作者T.S.

