Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatten for content files not working #6213

Closed
liushuanggang opened this issue Nov 22, 2017 · 7 comments
Closed

flatten for content files not working #6213

liushuanggang opened this issue Nov 22, 2017 · 7 comments
Labels
Area:ContentFiles PackageReference contentFiles folder Resolution:Question This issues appears to be a question, not a product defect Type:Bug

Comments

@liushuanggang
Copy link

Create a nuspec like the following:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>TestContentFile</id>
    <version>3.0.0</version>
    <authors>TestContentFile</authors>
    <owners>TestContentFile</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework=".NETStandard2.0" />
    </dependencies>
    <contentFiles>
      <files include="any/netstandard2.0/RemoveMe/TestFile.txt" buildAction="content" flatten="true" copyToOutput="false"/>
    </contentFiles>
  </metadata>

  <files>
    <file src="contentFiles/any/netstandard2.0/RemoveMe/TestFile.txt" target="contentFiles/any/netstandard2.0/RemoveMe/TestFile.txt" />
  </files>
</package>

It packs properly, but the argument flatten="true" did not work as expected after install the packed packaged to the project.

According to the description of flatten,

A Boolean indicating whether to copy content items to a single folder in the build output (true), or to preserve the folder structure in the package (false). The default is false.

And NuGet ContentFiles Demystified:

Should the files be all delivered to the root folder of the project or should they keep the folder structure that they were packaged in. The default value is false, which indicates they should create (if necessary) and keep the same structure they have after the TFM folder in the pacakge.

So if I set the flatten="true", after install this package to project, the TestFile.txt file should be delivered to the root folder of the project. Am I right? But after install this package to project, I still got the that file in the folder RemoveMe.

Besides, I also test other argument buildAction="content" copyToOutput="false", both of them works fine.

NuGet product used: NuGet.exe

NuGet version: 4.1.0

VS version (if appropriate): VS2017 15.4.4

OS version (i.e. win10 v1607 (14393.321)): Win 10 1703

Worked before? If so, with which NuGet version:

Detailed repro steps so we can see the same problem

  1. Create a .netstand project with VS2017, add a folder RemoveMe with a test file TestFile.txt in it.

  2. set true in the project file for test file.

  <ItemGroup>
    <Content Include="RemoveMe\ContentFile.txt">
      <PackageFlatten>true</PackageFlatten>
    </Content>
  </ItemGroup>

  1. Generat nuget package by VS, then install this package to another .net standard project.

Sample Project:

I share the onedrive link here, so that you can pack the .nuspec file directly:

https://1drv.ms/f/s!Ai1sp_yvodHfgQirLftPPOso7tV1

@PatoBeltran
Copy link

@rohit21agrawal can you please take a look into this?

@rohit21agrawal
Copy link
Contributor

sounds like pack is doing the right thing (@liushuanggang can you paste the nuspec file generated in the nupkg here to verify?) ...this will be a restore bug (for triaging purposes)

@rohit21agrawal rohit21agrawal added Functionality:Restore Area:ContentFiles PackageReference contentFiles folder and removed Functionality:Pack labels Nov 27, 2017
@liushuanggang
Copy link
Author

liushuanggang commented Nov 28, 2017

@rohit21agrawal, Sorry later reply. I have pasted my nuspec file below. And I have provided my test sample with one driver:

https://1drv.ms/f/s!Ai1sp_yvodHfgQirLftPPOso7tV1

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>TestContentFile</id>
    <version>3.0.0</version>
    <authors>TestContentFile</authors>
    <owners>TestContentFile</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework=".NETStandard2.0" />
    </dependencies>
    <contentFiles>
      <files include="any/netstandard2.0/RemoveMe/TestFile.txt" buildAction="content" flatten="true" copyToOutput="false"/>
    </contentFiles>
  </metadata>

  <files>
    <file src="contentFiles/any/netstandard2.0/RemoveMe/TestFile.txt" target="contentFiles/any/netstandard2.0/RemoveMe/TestFile.txt" />
  </files>
</package>

@rohit21agrawal
Copy link
Contributor

seems like the <Link> metadata for the contentFile written out in the .g.props file (inside the obj folder) has the wrong value and does not respect the flatten property.

@jainaashish
Copy link
Contributor

flatten flag only works when copyToOutput flag is set to true. I've updated the documentation to reflect the same.

@jainaashish jainaashish added the Resolution:Question This issues appears to be a question, not a product defect label Jan 10, 2018
@maxcherednik
Copy link

maxcherednik commented Mar 28, 2020

Still does not work for me.

<contentFiles>
      <files include="any/net472/bin/Release/net472/config.json" buildAction="Content" copyToOutput="true" flatten="true" />
    </contentFiles>

@MattiasEppler
Copy link

  <ItemGroup>
    <Content Include="native\*">
      <PackageCopyToOutput>true</PackageCopyToOutput>
      <PackageFlatten>true</PackageFlatten>
    </Content>
  </ItemGroup>

PackageFlatten works only if the consuming project is a .net Framework Project. If you use the new core format csproject Fille (sdk) the files are not flatten in the output directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:ContentFiles PackageReference contentFiles folder Resolution:Question This issues appears to be a question, not a product defect Type:Bug
Projects
None yet
Development

No branches or pull requests

6 participants