3

I have a clean VS 2019 project targeting .NET Framework 4.5 referencing Sitecore.Kernel and Sitecore.ContentSearch packages (specifically v8.0.150812) via NuGet using PackageReference. However, I get build errors in that the Sitecore types or namespaces cannot be found.

This is the project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net45</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Sitecore.ContentSearch" Version="8.0.150812">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Sitecore.Kernel" Version="8.0.150812">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
</Project>

This is my class:

using Sitecore.ContentSearch;
using Sitecore.ContentSearch.SearchTypes;

namespace TheValley.Sc.Modules.Search.SearchTypes
{
    public class CustomSearchResultItem : SearchResultItem
    {
        [IndexField("_foo")]
        public string Foo { get; set; }
    }
}

This is what I see in Solution Explorer:

Solution Explorer

This is the build output:

CustomSearchResultItem.cs(1,7,1,15): error CS0246: The type or namespace name 'Sitecore' could not be found (are you missing a using directive or an assembly reference?) CustomSearchResultItem.cs(2,7,2,15): error CS0246: The type or namespace name 'Sitecore' could not be found (are you missing a using directive or an assembly reference?) CustomSearchResultItem.cs(6,43,6,59): error CS0246: The type or namespace name 'SearchResultItem' could not be found (are you missing a using directive or an assembly reference?) CustomSearchResultItem.cs(8,10,8,20): error CS0246: The type or namespace name 'IndexFieldAttribute' could not be found (are you missing a using directive or an assembly reference?) CustomSearchResultItem.cs(8,10,8,20): error CS0246: The type or namespace name 'IndexField' could not be found (are you missing a using directive or an assembly reference?)

It is necessary for me to reference Sitecore 8.0 packages. No other restrictions. Any assistance greatly appreciated.

0

I recreated the project from scratch on another system, and for some as-yet-unknown reason, the PrivateAssets and IncludeAssets elements were not added when I added the Sitecore package references, and the project built successfully.

I then proceeded to remove these elements from my original project, and it then also built successfully. So, this appears to be the problem. It may not be Sitecore-specific as this solution was also the case for a similar issue here. A bug in the "weaver"?

So, the solution is just to remove the PrivateAssets and IncludeAssets elements from the PackageReference nodes in the project file.

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.