.netlinuxmononugetxbuild

How to add a missing assembly reference for xbuild? (Mono/Linux)


We have a C# project that builds perfectly well in Visual Studio on Windows and in TeamCity.

I try to build it like this on Linux, using Mono's xbuild:

MONO_IOMAP=case xbuild BuildAll.sln

The build fails, with 2 warnings and 7 errors, all of them about XmlDiffPatch.

The warnings:

/usr/lib/mono/4.5/Microsoft.Common.targets:  warning : Reference 'XmlDiffPatch, Version=1.0.8.28, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' not resolved

The errors:

***REDACTED***: error CS0234: The type or namespace name `XmlDiffPatch' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?

There are a couple of .cs files with

using Microsoft.XmlDiffPatch;

I have this in a .csproj file:

  <ItemGroup>
    <Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Security" />
    <Reference Include="System.Xml" />
    <Reference Include="XmlDiffPatch, Version=1.0.8.28, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </ItemGroup>
  ...
  <ItemGroup>
    <None Include="lib\XmlDiffPatch.dll" />
  </ItemGroup>

I have confirmed that a file lib\XmlDiffPatch.dll indeed exists.

The project has several modules (sorry, I don't know the exact .NET parlance, I come from a Java/Maven background) and the warnings/errors only occur in the modules that have a lib directory.

What do I need to do, to make this project build on Linux with Mono? My best guess is that the .csproj files are missing something so they cannot find the required .dll.

I looked at similar questions but they essentially say "just add a reference" without explaining how to do that on Linux. I don't have a "solutions explorer" or anything.

I should add that I am not using monodevelop, this is all console and editing files with vi.

I would also like to add that any changes to .csproj or other files should still be compatible with Windows.

EDIT

I don't know if it is helpful, but I noticed that the required version of XmlDiffPatch is also available on NuGet. Our C# project currently does not use NuGet at all, but I am certainly open for suggestions - as long as it only requires editing files on Linux and it will automagically work in Visual Studio after the Windows devs pull my commit.


Solution

  • You can add a HintPath to the .csproj so when MSBuild/xbuild passes the assembly references to csc/mcs it will be found:

    <Reference Include="XmlDiffPatch, Version=1.0.8.28, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" >
     <HintPath>lib\XmlDiffPatch.dll</HintPath>
    </Reference>
    

    Note: Edit the path so it is found relative to where the .csproj is located at (assuming the lib directory from your question).

    https://msdn.microsoft.com/en-us/library/bb629388.aspx

    HintPath | Optional string. | Relative or absolute path of the assembly.