12
votes

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?

8

8 Answers

14
votes

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>
10
votes

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".
5
votes

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.

5
votes

My mistake was that I added embedded resource while simulator with app was running.

Soo... I had THIS added automatically inside .csproj file:

<EmbeddedResource Include="**/*" />

Remove it, and then everything should be fine

0
votes

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

0
votes

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.

0
votes

It happened to me in MS Visual Studio for Mac after I have added two font files as embedded resources.

These files were titled with the same prefix (Lora-Regular.ttf & Lora-Bold.ttf) and it looks like my IDE did handle this in a bad way.

Indeed, the following weird line was inserted in my .csproj file :

<EmbeddedResource Include="**/*" />

All I did was removing this line and error disapeared.

0
votes

for me unloading and reloading project again worked!