0

Given: My local system references MSBuild at "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSbuild.exe". My automated build server (Jenkins) does not have this version of MSBuild so I used chocolatey to download microsoft-build-tools.

Problem: My visual studio project compiles successfully locally but won't compile successfully on my automated build server (Jenkins) due to a ReferenceAssembly error:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

I've searched online and found a possible solution https://developercommunity.visualstudio.com/content/problem/137779/the-getreferencenearesttargetframeworktask-task-wa.html where the powershell script modifies Microsoft Build Tools installer:

Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList 'modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" --quiet --add Microsoft.VisualStudio.Component.NuGet.BuildTools --add Microsoft.Net.Component.4.6.2.TargetingPack --norestart --force' -Wait -PassThru

I ran the script and I could see that it modifies the installer to select the specified target 4.6.2. However, the target package 4.6.2 is not present in the path "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework". I think it successfully downloaded the package one time but I deleted it to see if it was reproducible in my build server (Jenkins).

I don't want to manually paste the v4.6.2 target package from my local system to the build server. Any ideas on how to resolve this reference assembly problem?

ChipNugget
  • 363
  • 1
  • 7
  • 17
  • is there any update for this issue, if your issue is solved or not please feel free to let me know :( – LoLance May 16 '19 at 06:04

1 Answers1

0

For "GetReferenceNearestTargetFrameworkTask":

You can use powershell to call installer.exe, and install the components you lack.

Also, you can start vs installer in your server and modify your build tools to install packages below:

enter image description here

Any ideas on how to resolve this reference assembly problem?

If they are unchecked, check them and click modify button to install them by vs installer.exe.

And if they are checked, uncheck them and click modify to remove completely. After that, check them to reinstall the 4.6.2 framework.

Update:

After my check the modify in the Get Tools and Features can't help resolve assembly while they should.This option can only work to install new framework(which not once installed) but not repair the 4.6.2 once installed but now broken.

Download this developer pack manually and run it can help resolve the missing packages.

In addition:I delete the v4.6.2 folder in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework and get it back by run the pack to repair.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • After modifying the installer by adding the 4.6.2 targeting pack, should I expect the v4.6.2 folder to appear in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework? – ChipNugget May 09 '19 at 18:12
  • @Steven Hi friend, please check my update. And sorry for the misunderstanding :( but i think the developer pack can help solve your issue after my test. Let me know if it works :) – LoLance May 10 '19 at 03:48
  • @Steven Hi friend, any update? If the issue is solved or not please feel free to let me know, I'll try my best to help. – LoLance May 13 '19 at 09:20