0

I created a new .NET XUnit Core Project, converted it .NET Framework 4.6.1 to be similar to rest of legacy solution and tried to add in a new test. I realized that I need Glass Mapper for an ISitecoreContext (which I think might be depreciated but we use it in our code), because this is a Sitecore solution with some custom code in various projects, so I tried to add the same Glass Mapper libraries. Therefore, I unloaded a couple of other projects, combed their project files to find the versions of Castle.Core, Glass.Mapper.Sc, and Sitecore Nuget packages, and then added those Nuget packages into my project.

However, now I can't add in Glass.Mapper.Sc namespace into my new test file. Glass.Mapper exists but not Glass.Mapper.Sc. The older projects are .NET Framework 4.6.1 and the Nuget package versions are the same. The only thing I can see different is that the old project uses "References" and the new project has the Nuget packages under Dependencies. I think the older projects just link to the solution's Nuget packages in the root's packages folder.

What am I missing in this project? Is this because I converted it from .net core to framework 4.6.1 in the project file? I thought new projects in C# had their own Nuget packages and assemblies instead of the solution having them? Is this because new projects are different in how they address References? I cannot alter the solution or other projects (because we are trying to fix up this legacy code). I am sure this is something silly I just overlooked or something fundamental I missed. Thank you in advance.

Ross Gustafson
  • 1,182
  • 3
  • 16
  • 32

2 Answers2

0

I had the similar issue. After adding Glass.Mapper.Sc package to a project I've manually added the reference to Glass.Mapper.Sc.dll which is located in packages\Glass.Mapper.Sc.Core.4.2.1.188\lib\100\ folder (it was not added to the project automatically after the package installation via NuGet package manager). Here is the piece of my .csproj file:

<ItemGroup>
...
<!-- This one has been added during the package installation via NuGet -->
<Reference Include="Glass.Mapper, Version=4.2.1.188, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\..\..\packages\Glass.Mapper.Sc.Core.4.2.1.188\lib\net45\Glass.Mapper.dll</HintPath>
</Reference>

<!-- This one I've added manually -->
<Reference Include="Glass.Mapper.Sc">
  <HintPath>..\..\..\..\packages\Glass.Mapper.Sc.Core.4.2.1.188\lib\100\Glass.Mapper.Sc.dll</HintPath>
</Reference>
  • In our solution we use an old project file format. In case if your .csproj is in "Microsoft.NET.Sdk" format, then probably it will look a bit different, but the idea is the same
Vitalii Ilchenko
  • 578
  • 1
  • 3
  • 7
0

In this case I think the reference to package Glass.Mapper.Sc.XX.MVC is missing.
To get it working for me in my projects that I'm upgrading, I had to have 2 package references: the MVC one and Glass.Mapper.Sc.Core

Neo_
  • 282
  • 2
  • 6