Why can't I create Shared Project in Visual Studio 2015?
Asked Answered
P

4

29

I downloaded visual studio community 2015. I tried to create a Shared Project and am getting an error:

enter image description here

Content from Microsoft.Windows.UI.Xaml.CSharp.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup Condition="'$(TargetPlatformVersion)'==''">
        <TargetPlatformVersion>8.0</TargetPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
        <RedirectionTarget>8.2</RedirectionTarget>
    </PropertyGroup>

    <PropertyGroup Condition="'$(RedirectionTarget)' == ''">
        <RedirectionTarget>$(TargetPlatformVersion)</RedirectionTarget>
    </PropertyGroup>

    <!-- Direct 8.0 projects to 8.1 targets to enable retargeting  -->
    <PropertyGroup Condition="'$(RedirectionTarget)' == '8.0'">
        <RedirectionTarget>8.1</RedirectionTarget>
    </PropertyGroup>

    <Import Project="$(RedirectionTarget)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>

I do not have folder with name 8.1

Pogy answered 22/7, 2015 at 14:5 Comment(4)
What kind of project (which project template)? What version of .NET is it set to target?Okun
@Okun Tamplate "Shared Project". Net 4.5.Pogy
have you installed the 8.1 Store app tools?Marsiella
This worked for me on Win7 using a pre-release of vs2015, but stopped working with the full release. I guess I'm waiting until Win10 comes out to continue on this project.Gyrus
H
35

One workaround is to make the following edits:

Open the file %ProgramFiles(x86)%\MSBuild\Microsoft\VisualStudio\v14.0\CodeSharing\Microsoft.CodeSharing.CSharp.targets (for Visual Basic the file is Microsoft.CodeSharing.VisualBasic.targets) and look for the following entries around line 8 -

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets')"/>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" Condition="!Exists('$(MSBuildExtensionsPath32)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets')" />    

Change these lines to the following -

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" Condition="false"/>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" Condition="true" />

Basically, undo the conditional import of the Xaml based shared projects.

This is (believe it or not) the advice I received from MS for this issue. I think it's related to an unclean upgrade of the RC (or earlier) versions to RTM and the selection of different options during install.


(Insert usual caveats about editing files that don't "belong" to you, take backups, and if you're not confident to make such edits, don't)

Hypoblast answered 28/7, 2015 at 9:41 Comment(3)
This solution worked for me. Had VS Enterprise 2015 RC 1 installed, then installed final release. Problem started when updated VS to support Xamarin projectsNelson
This worked for me running VS2015 Enterprise. Seems like a bit of an oversight on Microsoft's part. Shared Projects really shouldn't have a dependency on the windows 8/8.1 project targetsNumbersnumbfish
This worked for me as well. I had an existing solution with a shared project that failed to load. I had to restart my visual studio for it to take effect. Trying to just reload the project didn't work.Beria
S
8

Try to copy 8.0 and 8.1 directories from C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v12.0 to C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0 (notice version number at the end).

It seems that those are missing in 2015 installation on windows 7.

You'll need to restart Visual Studio after that.

Selhorst answered 28/7, 2015 at 9:23 Comment(1)
This worked for me as well. The 8.0 and 8.1 directories were indeed missing and copying them over stopped the error from occurring. Thanks!Subcontinent
G
7

To fix this issue install the Windows 8/8.1 Project templates.

All I did was:

  1. Open VS 2015
  2. Click File->New->Project
  3. Choose the only Project template under Windows 8

This will launch Visual Studio setup where you can install the templates that are missing.

Then you can create your Project.

Gemology answered 22/7, 2015 at 17:49 Comment(4)
Worked for me! Thanks. However this feels like it must be overkill as I had to install an extra 5Gb of SDKs (I needed both options to get past the error). I was getting this error with a File-New Xamarin.Forms project but don't actually intend on supporting Win8.1 :(Grundyism
@RobBird: It also doesn't work if you are at a company that runs Windows 7. The project templates are simply unavailable.Chess
I received this link from Microsoft Connect to workaround the issue: connect.microsoft.com/VisualStudio/feedback/details/1578602/…Gemology
I got this to work on Windows 7 by following this answer and then copying the newly created folder C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\8.2 to C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\8.1 - the encyclopaedic download added the 8.2 folder but not the 8.1.Cronyism
V
7

This is not a hard problem. Mr. Kriper (the original asker of the question) likely installed using the "Default Install" for his version of Visual Studio 2015. Mr. Kondrasovas in Answer 2 points to needing to install more components. His approach resulted in a Visual Studio displaying a setup utility error which is no fault of Mr. Kondrasovas. Mr. Kondrasovas answer is likely correct if you do not encounter an error (I have no way to verify the answer).

The solution is to go to Control Panel | Programs | Uninstall a program. Select Visual Studio 2015 and "Modify" the installed instance of Visual Studio 2015:

[sorry I cannot show the image b/c I do not have a 10 for a reputation and StackOverflow.com is blocking me]

The previous (imaginary) screenshot is from the default install of Visual Studio 2015 Professional. You can mess around and figure out the exact feature to install or if you have the disk space, simply click on "Select All" and then "Next". Hint: the "Next" button is not enabled until a change is made to the selected components of Visual Studio 2015.

If you want to see the missing image a complete write up, I wrote a blog post on the issue: http://www.softwarepronto.com/2015/08/visual-studio-2015-error-adding-shared.html

Vermicide answered 22/8, 2015 at 16:49 Comment(2)
Sorry - just noticed your answer, and wanted to offer a little meta-advice - if you want to refer to someone else's answer's on here, it's better to link to the answer. Every answer has a share link at the bottom from which you can obtain a usable URL. Because "Answer 2", or the more usual "answer above" or whatever is subject to change - answers move around due to voting (generally up and down) and/or acceptance (promotes an answer to the top) and/or randomization (answers with equal score are not guaranteed to appear in a particular order).Hypoblast
After Modify(= Repair) VS installation, VS 2015 loads Shared project normally.Qintar

© 2022 - 2024 — McMap. All rights reserved.