6

My Windows app consists of 4 projects targeting Windows 8.1 and several testing projects:

Screenshot of solution projects

The "...App.Core" project was previously a Windows 8 project, which also targeted the .Net 4.5 framework. But because of this, there was some async features that couldn't be used.

We now need full async ability and the project has been re-targeted for only Windows8.1.

However, doing that broke the "...App.Core.Tests" project, which is a .Net 4.5 test project. It was referencing the App.Core project, and the reference is now broken.

Question: Is there a way to target the Windows 8.1 project from the Test project (without having to create a new test project)? The test project has a considerable number of tests, folders, and nuget package references that would be a major pain to have to transfer to a new project.

If I try to add the reference now, I get the annoyingly terse "Unable to add a reference to project 'MyProject.App.Core'."

Also, retargeting the App.Core project means updating the targets of the other 8.1 projects and reinstalling every nuget package for every project. Which is why I would rather solve this another way.. if there is one.

Is there some limitation of a .Net 4.5 project being able to reference a Windows 8.1 project? Or maybe I'm just doing something incorrectly.

Update

Based on the comment below from @PiLHA, I added .NET 4.5.1 as a target. It changed the library type from "Windows 8.1" to "Portable", but it broke all the async calls.

reference change

Note: I have Microsoft.Bcl v1.1.10, Microsoft.Bcl.Async v1.0.68, and Microsoft.Bcl.Build v1.0.21 added as nuget packages to the "MyProject.App.Core" project.

jwatts1980
  • 7,254
  • 2
  • 28
  • 44
  • You can not switch to a version above 4.5 (perhaps 4.5.1)? Have you tried setting up the target framework in the project properties for another version and then back to default? What error/incompatibility message do you receive from IDE? – PiLHA May 19 '17 at 19:04
  • @PiLHA the retargetting process for these projects in VS is kind of brutal. Lots of uninstalling and resintalling of nuget packages, and matching of versions, then cascading those updates through the other projects. That said, I will take a look at what happens if I try to add 4.5.1 as a reference to the Core project. I *think* I tried that already, and it broke the WinRT project reference... – jwatts1980 May 25 '17 at 15:54
  • 1
    There are multiple reasons for a reference to be broken. From a very simple one like a version mismatch to a very painful one because of a CLR mismatch. 95% of all problem are simple problems. But you don't give anybody a chance to post the simple answer as long as you don't tell us *everything* you know about the build failure. – Hans Passant May 25 '17 at 16:08
  • @HansPassant The project reference under "References" had a yellow triangle. I do not remember the exact build error, but I believe it was the standard ones you get when your project is trying to reference namespaces it can't see (ie., there were a LOT of errors). In my initial attempt to repair the issue, I right clicked the reference, removed it and went to re-add it. The error now is "Unable to add a reference to project 'MyProject.App.Core'". – jwatts1980 May 26 '17 at 02:41
  • @PiLHA See my question update – jwatts1980 May 26 '17 at 16:06
  • @jwatts1980 Now can you already compile the project with the framework change? Did the migration to 4.5.1 work? In regards to async errors, see if one of these can help https://stackoverflow.com/questions/11853812/task-does-not-contain-a-definition-for-getawaiter and https://stackoverflow.com/questions/38570858/does-not-contain-a-definition-for-getawaiter – PiLHA May 26 '17 at 19:01
  • @PiLHA I updated the project to also target .Net 4.5.1, and there was initially no issue. I built the project by itself (not the solution), and that's when the long list of async errors appeared. I'll take a look at the links... – jwatts1980 May 26 '17 at 19:05
  • @PiLHA neither of those links had relevant answers. These async calls build and work fine when I remove 4.5.1 as a target. I thought maybe there was a conflict between 4.5.1 and Microsoft.Bcl, but I can't remove Bcl because I'm using Flurl.Http (via nuget) which requires the Bcl libraries. – jwatts1980 May 26 '17 at 19:48
  • @jwatts1980 Very intriguing. I do not know what else to suggest, my intuition says it's some compatibility problem for libraries. – PiLHA May 26 '17 at 19:57

2 Answers2

2

Try this: Right click on your solution file in Solution Explorer window, click Add and then select Existing Project.

enter image description here

Once the project is a part of the solution, you will be able to add project reference.

lax1089
  • 3,403
  • 3
  • 17
  • 37
  • The project is already apart of the solution. In reference to the image I posted, the App.Core project is being referenced by every other project with "Windows 8.1" as the suffix, with no issues. The problem is that "Tests\MyProject.App.Core.Tests" cannot reference it. I get the "Unable to add a reference to project 'MyProject.App.Core'" error. – jwatts1980 May 26 '17 at 15:46
  • For completion sake, I tried this and received the message "The project 'MyProject.App.Core' cannot be added to the solution because it is already a member of the solution." – jwatts1980 May 26 '17 at 18:51
2

Take a look at the project file itself and see if there is something odd in the references group. Following link Cannot Edit or Add Path to Reference File in Visual Studio 2010 discusses manually editing a project file. I usually just open up the project file in a text editor. Look for ItemGroup, and the project's references will be included in that group. You can also try to manually add the reference this way.

help-info.de
  • 6,695
  • 16
  • 39
  • 41