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

查看:201
本文介绍了显示在解决方案资源管理器中使用.targets文件添加的NuGet包项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于以下问题:防止在NuGet content和contentFiles文件夹中重复文件,我正在使用build/Project.targets文件我的NuGet软件包中添加一些文件到项目构建输出中.喜欢:

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

现在,我实际上希望这些文件在 Solution Explorer 中可见,以便开发人员可以调整项目属性.但是将<Visible>标记设置为true无效.这有可能吗?

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. Is this even possible?

即使采用完全不同的方法,我仍然会很高兴,该方法仍然允许NuGet包将文件添加到packages.configPackageReference格式的项目构建输出中,但以 Solution Explorer显示文件.

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.

推荐答案

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

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

恐怕您无法通过使用.targets文件来执行此类操作.那是因为当您使用.target文件添加项目时,该项目已像添加为链接"一样添加到了您的项目中.这意味着该项目尚未真正添加到您的项目中.因此它不会显示在解决方案资源管理器中.

I am afraid you could not do such things by using .targets file. That because when you add item by using .target file, this item was added to your project like "Add As Link". That means this item hasn't really been added to your project. So it is not show in Solution Explorer.

要解决此问题,您可以创建两个nuget程序包,对于packages.config格式使用nuget content,对于PackageReference格式使用contentFiles.

To resolve this issue, you can create two nuget packages, using nuget content for packages.config formats and contentFiles for PackageReference formats.

希望这会有所帮助.

这篇关于显示在解决方案资源管理器中使用.targets文件添加的NuGet包项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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