简体   繁体   中英

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

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?

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

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 (eg: 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.

In the project that you are trying to reference, make sure the TargetFrameworks moniker doesn't contain .NET Core or .NET Framework .

  1. Right mouse button click on the project you are referencing.
  2. Edit Project File
  3. Find <TargetFrameworks>
  4. Remove the targets you don't need. For UWP you may leave only the .NET Standard 2.0 target:
<TargetFrameworks>netstandard2.0</TargetFrameworks>

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM