如何从其他项目添加对共享代码项目(.shproj)的引用

时间:2022-10-30 13:59:01

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 were created.

当我在Visual Studio中创建一个新的通用应用程序项目时,它创建了一个共享项目,让我在创建的Windows Phone 8.1和Windows 8.1项目之间共享代码。

Now I have other projects that I would also like to use that shared code. However, I do not see a way to add select that project in the "Add Reference..." window.

现在我还有其他项目,我也想使用共享代码。但是,我没有看到在“添加引用...”窗口中添加选择该项目的方法。

If I try to copy the reference from one of the existing projects I get the error:

如果我尝试从其中一个现有项目复制引用,我会收到错误:

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

灾难性故障(HRESULT异常:0x8000FFFF(E_UNEXPECTED))

when I click 'Paste Reference'. How do I reference the shared project from other projects?

当我点击“粘贴参考”时。如何从其他项目中引用共享项目?

3 个解决方案

#1


32  

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

在项目文件的底部附近(例如,.csproj),可能已经存在 元素,例如

<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.

Label属性设置为“Shared”非常重要。如果将其设置为其他内容,则Visual Studio将不会将其识别为共享项目,并且不会显示在“引用”下。应将项目设置为相应“.projitems”文件的路径。

#2


2  

Visual Studio 2017:

Visual Studio 2017:

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

右键单击“解决方案资源管理器”中的“引用”或“依赖项”项,然后选择“添加引用...”

如何从其他项目添加对共享代码项目(.shproj)的引用

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

参考管理器将打开。单击“参考管理器”左侧的“共享项目”

如何从其他项目添加对共享代码项目(.shproj)的引用

Then select your project and click OK.

然后选择您的项目并单击“确定”。

#3


-2  

Check out the Shared Project Reference Manager extension.

查看Shared Project Reference Manager扩展。

#1


32  

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

在项目文件的底部附近(例如,.csproj),可能已经存在 元素,例如

<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.

Label属性设置为“Shared”非常重要。如果将其设置为其他内容,则Visual Studio将不会将其识别为共享项目,并且不会显示在“引用”下。应将项目设置为相应“.projitems”文件的路径。

#2


2  

Visual Studio 2017:

Visual Studio 2017:

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

右键单击“解决方案资源管理器”中的“引用”或“依赖项”项,然后选择“添加引用...”

如何从其他项目添加对共享代码项目(.shproj)的引用

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

参考管理器将打开。单击“参考管理器”左侧的“共享项目”

如何从其他项目添加对共享代码项目(.shproj)的引用

Then select your project and click OK.

然后选择您的项目并单击“确定”。

#3


-2  

Check out the Shared Project Reference Manager extension.

查看Shared Project Reference Manager扩展。