Duplicate 'EmbeddedResource' items were included after migrate to .NET Standard?

橙三吉。 提交于 2020-05-26 12:58:49

问题


Using VS 2017 15.4.0

Following James Montemagno "Upgrading to Xamarin.Forms to .NET Standard"

https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard?ocid=player

When trying to Clean/Build I am receiving the error:

Severity Code Description Project File Line Suppression State Error 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: 'App.xaml'; 'MainPage.xaml' App5.core C:\Program Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets 274

Any solution please?


回答1:


Found the solution... Right click on the new .NET Standard project I have created "App5" and choose Edit App5.csproj I have deleted this code from the file and the error gone.

      <ItemGroup>
  <EmbeddedResource Include="App.xaml">
    <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
  </EmbeddedResource>
  <EmbeddedResource Include="MainPage.xaml">
    <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
  </EmbeddedResource>
</ItemGroup>



回答2:


I found various suggestions, but this answer was easily the best for me, both in simplicity and elegance:

  • In Solution Explorer, enable "Show All Files". This displays all files in each folder, including those excluded from the project.

For each item listed in the error message:

  • Exclude from project
  • Include in project

Then

  • In Solution Explorer, disable "Show All Files".



回答3:


According to bugzilla of xamarin at some point you were required to insert to make it work with the new csproj format.

 <ItemGroup>
    <!-- https://bugzilla.xamarin.com/show_bug.cgi?id=55591 -->
    <None Remove="**\*.xaml" />

    <Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
    <EmbeddedResource Include="**\*.xaml" SubType="Designer" Generator="MSBuild:UpdateDesignTimeXaml" />
  </ItemGroup>

Source

I would imagine that xamarin decided to add that to the default build targets now.

So to fix it you have to do the following:

  • Open your shared .csproj file.

  • Remove all Itemgroups related to adding xaml pages and *.cs

  • clean + rebuild.




回答4:


Try to clean it manually with these steps:

  • Close your VS
  • remove bin and obj folders from iOS, Android and the Common (Your project name) folder.
  • remove all content from the packages folder
  • open a terminal, navigate to your projects folder and type nuget locals all -clear
  • then type nuget restore

and finally open VS again and let me know if the problem still exists




回答5:


For me issue was in one file name. I used underscore (_) in the filename. I was working with file name AppResource.zh_cn.resx. May be it could help someone.



来源:https://stackoverflow.com/questions/46748950/duplicate-embeddedresource-items-were-included-after-migrate-to-net-standard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!