C# UWP - Can't add reference to project in sam

2019-04-06 03:32发布

问题:

I need to write a UI for an API utility that I need to use. I have created a new Universal Windows App for the UI, added the API utility project to the solution and now need to reference the API utility from the UWP project - but I just get 'Unable to add a reference to project 'XXX'.

If I create a Windows Forms Application or a console project and add that to the solution, I can do the referencing, no probs.

What is it about UWP that I don't understand?

回答1:

You should create a portable class library for your API utility.

See MSDN: https://msdn.microsoft.com/en-us/library/gg597391(v=vs.110).aspx



回答2:

When coding UWP , to build library that can be referenced by a same-solution UI UWP project I need to use a specific library project template (e.g.: by doing Add new Project | Windows | Class Library (Universal Windows)) , that's what worked for me ( I assume you have UWP SDK installed ) so if you have your .dll source maybe you should try to recompile it using that project format. Hope it helps.



回答3:

There are two ways to provide reference to c# projects.

Select project -> Right click References -> Add reference
1. via .dll : Browse for Assemblies(.dll files) and select your desired file -> OK
2. via .csproj : Select Projects/Shared Projects from left menu -> browse for the .csproj files (Note: choose file-filter as 'All files' to make them visible) -> OK



回答4:

When adding the Test Project, instead of going to "Test" and selecting "Unit Test Project (.Net Framework)"… Go to "Windows Universal" and select "Unit Test App (Universal Windows)"

If you select this project, then you will be able to add a reference to your UWP project.