如何从解决方案中引用项目? [英] How to reference a project out of solution?

查看:73
本文介绍了如何从解决方案中引用项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio C#解决方案,其中包含一些项目.其中一个项目需要引用另一个不属于解决方案的项目.

一开始我是在参考dll:

 < ItemGroup><参考Include ="ExternalProj1,版本= 1.0.0.0,区域性=中性,处理器体系结构= MSIL">< SpecificVersion>假</SpecificVersion>< HintPath> .. \ .. \ Proj1 \ ExternalProj1.dll</HintPath></参考></ItemGroup> 

但是,我必须引用项目,以便那些项目可以生成其dll.实际上,如果我引用dll并且尚未创建,则需要分别构建这些项目.

但是在引用项目时:

 < ItemGroup>< ProjectReference Include =".. \ .. \ Proj1 \ ExternalProj1"><项目> {3341b552-a569-4313-aabc-34452fff60ac}</项目><名称> ExternalProj1</名称></ProjectReference></ItemGroup> 

但是,在构建编译器时找不到这些程序集.奇怪的是,报告构建过程已成功完成,但错误窗口报告了一个警告:

找不到引用的组件ExternalProj.

那么,我在做什么错?谢谢

解决方案

我看到您正在使用 ProjectReference ,这是我在普通(非.NET)C ++项目中所熟悉的.Include属性需要命名文件,而不仅仅是基本名称.例如

 < ProjectReference Include =".. \ .. \ Proj1 \ ExternalProj1.vcxproj"> 

也就是说, ProjectReference 不是 Reference .请参见常见的MSBuild项目项

此外,如果未为该项目指定,则通过提供的props文件确定用于确定是否自动链接LIB的元数据.受管项目甚至产生了LIB吗?因此,这(在文件名正确的情况下)应使被提名的项目也作为依赖项构建,而对其产品执行某些操作则完全是另一个问题.

请尝试从MSBuild.exe命令行(而不是IDE)进行构建,以在IDE弄乱事情或添加更多问题来解决之前查看纯行为.然后,向其提供您想要的特定proj文件,而不是解决方案"文件..sln文件是一个奇怪的野兽,不仅可能在sln中不存在项目引用,而且根本没有sln文件的固有概念.除了要在IDE中显示的项目列表之外,它是一个动态转换为主项目的魔术文件,可让您单独命名各个目标,而不必知道哪个项目文件(或指向它的路径)足够方便,但主要是为了根据 The Books 与VSBuild兼容.因此,避免这样做,至少是简化事情以在探索阶段获得所需的行为.然后,如果您仍然想要它们,请添加所有并发症:).

I have a Visual Studio C# solution which consists of some projects. One of the projects needs to reference another project which is not part of the solution.

At the beginning I was referencing dlls:

<ItemGroup>
  <Reference Include="ExternalProj1, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>..\..\Proj1\ExternalProj1.dll</HintPath>
  </Reference>
</ItemGroup>

However I must reference projects so that those will generate their dlls. In fact If I reference dlls and they have not been created, I need to build those projects separately.

However when referencing projects:

<ItemGroup>
  <ProjectReference Include="..\..\Proj1\ExternalProj1">
    <Project>{3341b552-a569-4313-aabc-34452fff60ac}</Project>
    <Name>ExternalProj1</Name>
  </ProjectReference>
</ItemGroup>

However when building the compiler cannot find those assemblies. The strange thing is that building process is reported as completed successfully but the error window reports one warning:

The referenced component ExternalProj could not be found.

So, what am I doing wrong? Thank you

解决方案

I see you are using ProjectReference, which is what I'm familiar with in plain (non-NET) C++ projects. The Include attribute needs to name the file, not just the base name; e.g.

<ProjectReference Include="..\..\Proj1\ExternalProj1.vcxproj">

That is, ProjectReference is not Reference. See Common MSBuild Project Items

Also, the metadata that determines whether to link the LIB automatically is determined via the supplied props files if it is not specified for that item. Is a managed project even producing a LIB? So this should (with the filename correct) cause the nominated project to be built also as a dependent, doing something with its products is another issue altogether.

Try building from MSBuild.exe command line, not the IDE, to see the pure behavior before the IDE messes things up or adds more issues to figure out. And, feed it the specific proj file you are wanting, not the "solution" file. The .sln file is a strange beast and not only is it possible to have project references not present in the sln, there is no inherent concept of a sln file at all. Other than a list of projects to show in the IDE, it is a magic file converted into a master proj on the fly that lets you name various targets individually without having to know which proj file (or the path to it) which is handy enough, but mainly there for compatibility with VSBuild according to The Books. So avoid it, at least to simplify things to get the behavior you want during the exploration stage. Then add any complications back in if you still want them :) .

这篇关于如何从解决方案中引用项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆