How do I add a reference to a Shared Code project (.shproj) from another project

后端 未结 5 2150
南笙
南笙 2020-12-10 10:19

When I created a new universal app project in Visual Studio it created a shared project that let me share code between the Windows Phone 8.1 and Windows 8.1 projects that we

相关标签:
5条回答
  • Check your version of Visual Studio. in VS2017 there was a bug fix for version 15.9 which will show the Shared Project selector. Click Tools -> Update to get the lastest version of VS

    0 讨论(0)
  • 2020-12-10 11:09

    In TargetProject.csproj file add that string:

    <Import Project="..\YourSharedProject\YourSharedProject.projitems" Label="Shared" Condition="Exists('..\YourSharedProject\YourSharedProject.projitems')" />
    
    0 讨论(0)
  • 2020-12-10 11:09

    Check out the Shared Project Reference Manager extension.

    0 讨论(0)
  • 2020-12-10 11:13

    Visual Studio 2017:

    Right-click the References or Dependencies item in the Solution Explorer and choose "Add Reference..."

    The Reference Manager will open. Click "Shared Project" on the left side of the Reference Manager

    Then select your project and click OK.

    0 讨论(0)
  • 2020-12-10 11:21

    Adding the reference will require editing the project files where you want to add it. If it helps, you can peak at the project file where it is already referenced to see a working example.

    Near the bottom of the project file (ex, a .csproj) there is likely already an <Import> element such as

    <Project ...>
      [...]
      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    </Project>
    

    You add the Shared project by adding another element like that for the Shared project. For example:

    <Project ...>
      [...]
      <Import Project="..\Shared\Shared.projitems" Label="Shared" />
      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    </Project>
    

    It is important for the Label attribute to be set to "Shared." If you set it to something else it will not be recognized as a Shared project by Visual Studio and will not appear under References. Project should be set to the path to the appropriate ".projitems" file.

    0 讨论(0)
提交回复
热议问题