Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 558
Martin Prikryl Avatar asked Mar 27 '18 07:03

Martin Prikryl


People also ask

Where are NuGet packages stored in a solution?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder.

How do I view NuGet package contents?

To open this file in the explorer, right-click on it. And choose open with, and then select NuGet Package Explorer.

How do I reference an existing NuGet package from a new project?

NET or . NET Core project. After you install a NuGet package, you can then make a reference to it in your code with the using <namespace> statement, where <namespace> is the name of package you're using. After you've made a reference, you can then call the package through its API.


1 Answers

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

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.

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

Hope this helps.

like image 135
Leo Liu-MSFT Avatar answered Oct 22 '22 20:10

Leo Liu-MSFT