Reputation: 233
I want to run a background task that will use a lot of the same code as the main project, so i have created a new project for my background task, and a new shared project for my shared code.
I have transferred all of my shared code to the shared code project, i have added the reference to my shared project into my main project and the project works.
I have then added a reference to my shared project into my background task project, built the solution and it works (works as in compiles).
As soon as i add the reference to my background task project into my main project, when i try to build the solution i get the following error:
A public type has a namespace ('BackgroundTask') that shares no common prefix with other namespaces ('SharedCode.Functions'). All types within a Windows Metadata file must exist in a sub namespace of the namespace that is implied by the file name. BackgroundTask C:\Users\User\documents\visual studio 2015\Projects\Project\BackgroundTask\WINMDEXP
If i dont add the reference to the background project within the main project and i try to run the background task, it fails.
In my background task project, at the top, i have included using SharedCode; And when the task runs, it just needs to make one call to the shared code:
await SharedCode.Check();
The background task project, doesnt need to use SharedCode.Functions directly, that would be called from within the SharedCode project itself.
Any ideas?
And just for reference, the shared code will make a http request and update a local database using SQLite.net-PCL
Upvotes: 2
Views: 347
Reputation: 3746
It seems that you are using an old 'shared' project template that was used on Windows 8 / Windows Phone 8.
In this kind of projects, the code is actually duplicated into the different parent projects meaning that even if you see three projects here, only two exe/dll will be generated. The code in the shared project will be copied into the windows and into the windows phone project.
To achieve what you are trying to do, you can simply create a regular class library (Universal Windows)
to host your shared code, a Windows Runtime Component (Universal Windows)
library to host the background task entry point and a Blank App (Universal Windows)
.
Both your background task and your app will reference the shared class library.
You can also leave all your shared code in the background task library (WinMD) and consume it from your application.
Upvotes: 0
Reputation: 65564
It seems there is a base namespace rule for shared projects and Runtime Components. (I've never heard of this before.)
Because of the way code generated form a runtime component is exported it must have a single root namespace. The easiest way to achieve this is to use project names with a common prefix before a dot.
So instead of having projects called
You call them (and set the root namespaces)
As an alternative you may make things much simpler for yourself if you might instead be able to use an in-process background task (depending on what your task does.)
Upvotes: 2