简体   繁体   English

显示在解决方案资源管理器中使用.targets文件添加的NuGet包项目

[英]Showing NuGet package item added using .targets file in Solution Explorer

Based on this question: Prevent duplicating files in NuGet content and contentFiles folders , I'm using build/Project.targets file of my NuGet package to add some files to project build output. 基于这个问题: 防止在NuGet内容和contentFiles文件夹中复制文件 ,我正在使用我的NuGet包的build/Project.targets文件将一些文件添加到项目构建输出中。 Like: 喜欢:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Content Include="$(MSBuildThisFileDirectory)..\tools\test.jpg">
      <Link>test.jpg</Link>
      <Visible>false</Visible>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>
</Project>

Now, I actually want those files to be visible in Solution Explorer , so that developer can tweak item properties. 现在,我实际上希望这些文件在解决方案资源管理器中可见,以便开发人员可以调整项目属性。 But setting the <Visible> tag to true makes no effect. 但是将<Visible>标记设置为true不起作用。 Is this even possible? 这甚至可能吗?


I'd be happy even with a completely different approach that still allows the NuGet package to add files to project build output for both packages.config and PackageReference formats, yet show the files in Solution Explorer . 我很高兴,即使一个完全不同的方法,仍然允许NuGet包添加文件到项目都生成输出packages.configPackageReference格式,但显示在Solution Explorer中的文件。

Showing NuGet package item added using .targets file in Solution Explorer 显示在解决方案资源管理器中使用.targets文件添加的NuGet包项目

I am afraid you could not do such things by using .targets file. 我担心你不能通过使用.targets文件来做这些事情。 That because when you add item by using .target file, this item was added to your project like "Add As Link". 这是因为当您使用.target文件添加项目时,此项目已添加到您的项目中,如“添加为链接”。 That means this item hasn't really been added to your project. 这意味着此项尚未真正添加到您的项目中。 So it is not show in Solution Explorer. 所以它不会在解决方案资源管理器中显示

To resolve this issue, you can create two nuget packages, using nuget content for packages.config formats and contentFiles for PackageReference formats. 要解决此问题,您可以使用nuget content for packages.config格式和contentFiles for PackageReference格式创建两个nuget包。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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