5
\$\begingroup\$

I'm looking for some suggestions on how to fix a strange bug i've been getting with System.net.http.dll.

For the record, builds work fine as i have the mcs.rsp file in the /Assets/ folder with "-r:System.Net.Http.dll" inside. The problem lies with Visual Studio and it's relation to Unity. I can add the reference to the dll by selecting "Analyzers" then hitting "Project" and Adding the dll found in:

C:\Program Files\Unity\Hub\Editor\2018.2.2f1\Editor\Data\MonoBleedingEdge\lib\mono\4.7.1-api\System.Net.Http.dll

But VS changes the reference instantly to:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.1\System.Net.Http.dll

Then after a short amount of time, the reference i made just gets automatically deleted.

I've tried clearing the VS Cache inside of AppData/Local/ as well as clearing everything but the Asset Folder in my unity project (including obj, library, .CSPROJ, .sln files etc.) But to no success.

Im using .NET 4.x in the project and it builds fine, its just that the VS reference keeps being deleted. so when it comes to "Attaching to Unity" i can't execute until i re-assign the "temporary" assembly reference.

I've tried updating VS, Reinstalling it as well as unity 2018.2.1 and Unity2018.2.2 to no success.

I'm all ears.

UPDATE: Problem has been fixed in 2018.3

\$\endgroup\$
  • 1
    \$\begingroup\$ I've read elsewhere about challenges with this particular dll. Does any of the advice in this thread help you? \$\endgroup\$ – DMGregory Aug 20 '18 at 10:44
  • \$\begingroup\$ Ah yes, that solution allows me to build the project fine within unity however is doesn't populate the reference within visual studio. I end up adding that reference manually, but it gets deleted after a short amount of time. \$\endgroup\$ – Nilmag Aug 20 '18 at 10:54
  • \$\begingroup\$ As an update, im still getting this problem... on 2018.2.16f1 \$\endgroup\$ – Nilmag Nov 27 '18 at 10:15
1
\$\begingroup\$

Unity will override the .csproj files every time it recompiles the scripts. To fix this, you must include a script that will listen for the generation of the project files event and add the reference manually. This is just a quick and dirty example, you can add a proper XML parser to do the job. Add this script in an Editor folder.

using SyntaxTree.VisualStudio.Unity.Bridge;
using System;
using UnityEditor;

[InitializeOnLoad] public class ReferenceRemovalProjectHook { static ReferenceRemovalProjectHook() { const string itemGroup = "<ItemGroup>"; const string systemNet = "<Reference Include=\"System.Net.Http\" />"; ProjectFilesGenerator.ProjectFileGeneration += (name, content) => { if (!content.Contains(systemNet) && content.Contains(itemGroup)) { int a = content.IndexOf(itemGroup, StringComparison.OrdinalIgnoreCase); content = content.Insert(a + itemGroup.Length, "\n " + systemNet); } return content; }; } }

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.