OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.36k stars 2.37k forks source link

.NET SDK Includes 'Embedded Resource' items on new Module scaffolding #13026

Open GadgetGeekUK opened 1 year ago

GadgetGeekUK commented 1 year ago

Describe the bug

Error on build (Visual Studio 2022 - latest version: 17.4.3):

NETSDK1022 Duplicate 'EmbeddedResource' items were included. The .NET SDK includes 'EmbeddedResource' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultEmbeddedResourceItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'Views\AboutIntroPart.Edit.cshtml'; 'Views\AboutIntroPart.liquid'; 'Views\AboutIntroPartSettings.Edit.cshtml'; 'Views\AboutIntroPart_Summary.liquid'; 'Views\Home\Index.cshtml'; 'Views_ViewImports.cshtml' C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets 201

To Reproduce

Steps to reproduce the behavior:

  1. Using the full Orchard source code
  2. Create a new Module with Part, using the command (as shown on https://docs.orchardcore.net/en/latest/docs/getting-started/templates/#create-a-new-cms-module)
  3. Build the module

Expected behavior

Module should build

Generated Project File:

No additional files added, everything comes from the code generation:

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="OrchardCore.Module.Targets" Version="1.5.0" />
    <PackageReference Include="OrchardCore.ContentManagement" Version="1.5.0" />
    <PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="1.5.0" />
    <PackageReference Include="OrchardCore.DisplayManagement" Version="1.5.0" />
  </ItemGroup>

</Project>

Workaround

Change the project file to reference the projects in the solution, further, disable the 'Nullable' option:

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
    <!--<Nullable>enable</Nullable>-->
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

  <ItemGroup>
    <!--
    <PackageReference Include="OrchardCore.Module.Targets" Version="1.5.0" />
    <PackageReference Include="OrchardCore.ContentManagement" Version="1.5.0" />
    <PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="1.5.0" />
    <PackageReference Include="OrchardCore.DisplayManagement" Version="1.5.0" />
    -->

    <ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />
    <ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement\OrchardCore.ContentManagement.csproj" />
    <ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentTypes.Abstractions\OrchardCore.ContentTypes.Abstractions.csproj" />
    <ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
  </ItemGroup>

</Project>
hishamco commented 1 year ago

The project templates used to create OC app / module without source code dependency

GadgetGeekUK commented 1 year ago

I realize that, hence why the generated project references the nuget version of OrchardCMS. However, I did not expect the error shown if module generation is used to create a new module within a fork of the source code. Its also a strange error, I'd have thought you could have used and built the generated module successfully once the code has been initially generated...

sebastienros commented 1 year ago

Can the module generation logic be clever to detect we are in OC's source code? Maybe by checking for the existing .Target/.Props files?