Share via

WinUI 3 cannot create a project build when adding a reference to a background task project

Anonymous
2023-06-23T11:47:44+00:00

The error appears after adding a reference to the background project to the UI project. The background project contains the same project references as the UI project. I tried to remove the repeated project references from the UI project , leaving them only in the background task project, but the error repeated itself

Error MSB4018 The "GenerateDepsFile" task failed unexpectedly.

System.ArgumentException: An item with the same key has already been added.

   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)

   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)

   at Microsoft.NET.Build.Tasks.SingleProjectInfo.CreateProjectReferenceInfos(IEnumerable1 referencePaths, IEnumerable1 referenceSatellitePaths, Func`2 isRuntimeAssembly)

   at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath)

   at Microsoft.NET.Build.Tasks.TaskBase.Execute()

   at Microsoft.NET.Build.Tasks.TaskWithAssemblyResolveHooks.Execute()

   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Windows for home | Windows 10 | Install and upgrade

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-11-25T16:17:52+00:00

    I reported in the mean time an error on the Visual Studio Developer web site.

    See here.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-11-24T19:10:16+00:00

    I have the same issue. It occurs when you add a OOP background task to a solution where both the background project and the WINUI-exe project needs references to the same 'library' projects inside the solution.

    In a WinUI/WindowsAppSdk desktop app a OOP background task must be defined in a seperate CsWinRTComponent library project (to add the WinRT.Host dlls) and the exe project must reference the background task project in order bring everything together in the app. Unless one copies the necessary code from the shared libraries into the background project I don't see any way to solve this. That of course is ridiculous.

    Did you find a solution in the mean time to overcome this?

    Was this answer helpful?

    0 comments No comments
  3. DaveM121 891.1K Reputation points Independent Advisor
    2023-06-23T12:19:30+00:00

    Hi Roman,

    I am Dave, I will help you with this.

    I apologize, Community is just a consumer forum, due to the scope of your question can you please post this question to our sister forum on Microsoft Q&A (The Software Developers Forum)

    Over there you will have access to a host of developers and programming experts and will get a knowledgeable and quick answer to this question.

    https://docs.microsoft.com/en-us/answers/index....

    Was this answer helpful?

    0 comments No comments