How to find the cause of: Xamarin.Forms targets have been imported multiple times

LesFergLesFerg NZMember ✭✭
edited November 2017 in Xamarin.Forms

I'm working my way thru the book "Creating Mobile Apps with Xamarin Forms" and a lot of the sample code requires some work to get it running, which is all very educational and helps me learn and remember. However I can't find the cause of this one;
Chapter 20, MandelbrotProgress, gives me an error in the Xamarin.Formsbook.Toolkit project:

Xamarin.Forms targets have been imported multiple times. Please check your project file and remove the duplicate import(s).

Can somebody point me at the root cause of this please. I cannot find any obvious duplicates in the project file, but there are some error conditions defined in there which I am suspicious of.

Also, is there a specific forum or support area for the above mentioned book?

Best Answers

  • LesFergLesFerg NZ ✭✭
    Accepted Answer

    Ok I picked an include statement in the project file and removed it, now it works.
    Is there a reason these project files are not quite correct for VS2017?

Answers

  • LesFergLesFerg NZMember ✭✭

    Forgot to add - I am skipping the Windows and WinPhone projects from the sample solution, and running the UWP project from VS2017 on windows 10.

  • LesFergLesFerg NZMember ✭✭
    Accepted Answer

    Ok I picked an include statement in the project file and removed it, now it works.
    Is there a reason these project files are not quite correct for VS2017?

  • Emixam23Emixam23 USMember ✭✭✭

    Whaaaaaaaaaat I don't get your answer, what did you do exactly?

    Thanks

  • Encountered the same problem in my Xamarin Forms UWP project. In my case, I had a .nuget.targets associated with my UWP project. In this file, there was a line to Xamarin Forms from the .nuget "assembly cache". After removing this line, my project again builds successfully.

  • jjtudujjtudu Member ✭✭

    I don't get your answer, what need to be done?

  • shalinasangashalinasanga USMember ✭✭

    After updating to Xamarin.Forms.2.5.0.121934 encounter this error. we are using portable class library. after commenting import of xamarin forms netstandard in droid proj file it start building.
    Do anyone know how to fix this ???

  • batmacibatmaci DEMember ✭✭✭✭✭

    @LesFerg said:
    Ok I picked an include statement in the project file and removed it, now it works.
    Is there a reason these project files are not quite correct for VS2017?

    Can you please give more details? is it for UWP? which include lines did you remove? i cant see any duplication or old version in my csproj file

  • DFoulkDFoulk USMember ✭✭

    I have these in my project... They don't appear to be duplicates of each other?

    packages.config

    <Error Condition="!Exists('..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.props'))" />
    <Error Condition="!Exists('..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.targets'))" />
    
    <Import Project="..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.props" Condition="Exists('..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.props')" />
    <Import Project="..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.targets" Condition="Exists('..\..\..\packages\Xamarin.Forms.2.5.0.122203\build\netstandard1.0\Xamarin.Forms.targets')" />
    
  • batmacibatmaci DEMember ✭✭✭✭✭

    @Chris_Lamont said:
    Right click on your project and select Edit Project File

    In the section that has all your imports, ie <Import Project="..\..\

    You will probably find that there are two imports of Xamarin.Forms, ie ...packages\Xamarin.Forms...

    You can delete one of them.

    I checked both PCL and UWP proj files and there is no duplication.

  • stijnvstijnv BEMember
    edited February 2018

    I managed to resolve this error by removing

    <Import Project="..\packages\Xamarin.Forms.2.5.0.121934\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.5.0.121934\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets')" />

    in the PCL project.

    Hope this helps!

  • CodeGrueCodeGrue USMember ✭✭

    Had this issue. Deleted the two files "Project.csproj.nuget.cache" and "Project.csproj.nuget.targets" to fix it.

  • anish_palanish_pal INMember ✭✭

    we are facing same issue..

  • Manikandan_SManikandan_S USMember ✭✭

    Any Solution?

  • Deleting bin and obj for the affected projects fixed it for me.

  • MatthewWaring.4722MatthewWaring.4722 GBUniversity ✭✭

    Phew.

  • bijingtonbijington Member ✭✭

    I had a similar issue in my iOS project however it seems I had left an old nuget packages.config file in the iOS project directory that was causing the duplicate import,

  • smrof_niramaxsmrof_niramax USMember ✭✭

    I also had recently a similar problem on iOS. Cleaning the solution, restarting Windows and Mac solved it

  • BoomShankarBoomShankar USMember ✭✭

    @Chris_Lamont said:
    Right click on your project and select Edit Project File

    In the section that has all your imports, ie <Import Project="..\..\

    You will probably find that there are two imports of Xamarin.Forms, ie ...packages\Xamarin.Forms...

    You can delete one of them.

    Yup. this worked perfectly. Thanks a lot :)

  • DanH2DanH2 USMember

    If you're like me and are encountering this error but do not have anything imported multiple times... you could try deleting the ".vs" folder at the solution level and the "obj" & "bin" folders for the project(s).

  • DFoulkDFoulk USMember ✭✭

    @DanH2 said:
    If you're like me and are encountering this error but do not have anything imported multiple times... you could try deleting the ".vs" folder at the solution level and the "obj" & "bin" folders for the project(s).

    This- I was able to just delete the obj and bin folders and restarted Visual Studio. I doubt many will run into this in the future, though, because I think this issue is isolated to projects using Xamarin.Forms 2.X and package.config...

  • dinobdinob USUniversity ✭✭✭

    None of my projects have project_name.nuget.props and project_name.nuget.targets files.

    What I see are lots of these files accross all projects in solution

    project_name.nuget.g.props 
    project_name.nuget.g.targets
    project_name.nuget.cache
    project_name.nuget.stamp
    
  • dinobdinob USUniversity ✭✭✭
    edited November 2018

    @batmaci said:
    Hi Everyone,

    for those who still have the error, please find the answer over here https://github.com/xamarin/Xamarin.Forms/issues/1587
    basically just remove th nuget.props and nuget.targets files next your UWP csproj file.

    @batmaci @MatthewWaring.4722 @DFoulk None of my projects have project_name.nuget.props and project_name.nuget.targets files.

    What I see are lots of these files across all projects in solution

    project_name.nuget.g.props 
    project_name.nuget.g.targets
    project_name.nuget.cache
    project_name.nuget.stamp
    

    I did this by closing my solution, exiting the IDE, then deleting all of these files (there were lots of them), I also deleted .vs, bin and obj folders in each project. Restarted the IDE, reloaded the solution. Still all 3 clean, build, rebuild fail with this XF001 error

  • dinobdinob USUniversity ✭✭✭

    @DFoulk said:

    @DanH2 said:
    If you're like me and are encountering this error but do not have anything imported multiple times... you could try deleting the ".vs" folder at the solution level and the "obj" & "bin" folders for the project(s).

    This- I was able to just delete the obj and bin folders and restarted Visual Studio. I doubt many will run into this in the future, though, because I think this issue is isolated to projects using Xamarin.Forms 2.X and package.config...

    @DFoulk This did not help, I tried multiple times, see my answer below to @batmaci

  • DFoulkDFoulk USMember ✭✭

    @dinob said:

    @DFoulk said:

    @DanH2 said:
    If you're like me and are encountering this error but do not have anything imported multiple times... you could try deleting the ".vs" folder at the solution level and the "obj" & "bin" folders for the project(s).

    This- I was able to just delete the obj and bin folders and restarted Visual Studio. I doubt many will run into this in the future, though, because I think this issue is isolated to projects using Xamarin.Forms 2.X and package.config...

    @DFoulk This did not help, I tried multiple times, see my answer below to @batmaci

    I'm sorry @dinob I'm not sure what answer you're pointing me to? That's okay though.

    It's unclear to me whether or not you've removed any duplicate imports manually. If you've done this and/or cleaned your solution properly, then perhaps it may help to:

    1. Uninstall all Nuget packages
    2. Ensure that no duplicate project references are present in your solution
    3. Clean your solution (properly)
    4. Install all of your necessary Nuget packages

    This process is kind of like using a hammer to set a thumbtack, but it has helped me in the past resolve issues. Think of it as a "full reset".

    Good luck!

  • dinobdinob USUniversity ✭✭✭

    In my case, none of these have helped. I was getting XF001 error each time I would add a specific package (Xamarin.EnableKeyboardEffect) because some of my projects weren't migrated to use PackageReferences instead of packages.config. After I removed these, XF001 error was gone.

  • GerryHGerryH USMember ✭✭✭

    Right click project, there is no such option "Edit Project File" - what platform are you on?

Sign In or Register to comment.