简体   繁体   中英

Visual Studio does not display references from targets in Solution Explorer

Here is a part of my .csproj:

<Project DefaultTargets="Build" InitialTargets="MyTarget" xmlns="...">
<Target Name="MyTarget" DependsOnTargets="Include_Ver1;Include_Ver2"/>

 <Target Name="Include_Ver1" Condition="...">
    <ItemGroup>
      <COMReference Include="Ref">      
         1st_Version
      </COMReference>
    </ItemGroup>
  </Target>

 <Target Name="Include_Ver2" Condition="...">
    <ItemGroup>
      <COMReference Include="Ref">      
         2nd_Version
      </COMReference>
    </ItemGroup>
  </Target>

I can use library functions and project builds correctly, but reference does not appear in "References" block inside visual studio solution explorer. How can I force Intellisense parse references in Targets?

Try with different References and below hintpath ,specific version node elements.Make sure the *.csproj is not write only under any Version control system like SVN etc.

 <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
        <Reference Include="Microsoft.Owin, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>..\..\Microsoft.Owin.dll</HintPath>
        </Reference>
    </ItemGroup>

VS doesn't display them because the solution explorer basically shows what it gets after parsing the project file. Parsing != executing, so the reference added in a target is not seen as it never executed - which makes sense, VS cannot guess if the target will even be executed or not and it cannot just start executing random builds to figure out if the reference will be added.

Do you really need a target? ItemGroups can have conditions too, maybe this is sufficient for you?

<ItemGroup Condition="...">
  <COMReference Include="Ref">      
     1st_Version
  </COMReference>
</ItemGroup>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM