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

content files are not being included in old format project #6675

Closed
canhazcodez opened this issue Mar 14, 2018 · 19 comments
Closed

content files are not being included in old format project #6675

canhazcodez opened this issue Mar 14, 2018 · 19 comments
Labels
Area:ContentFiles PackageReference contentFiles folder WaitingForCustomer Applied when a NuGet triage person needs more info from the OP

Comments

@canhazcodez
Copy link

canhazcodez commented Mar 14, 2018

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):

NuGet Version: 4.3.0.4406

VS version (if appropriate): 2017

OS version: Version 10.0.14393

I am trying to create a nuget package that will add content to a project. I have followed many online tutorials on how to do it, and ended up with the following:

folder layout>

NugetPackage\
->NugetPackage.nuspec
->TestData\
-->some files in subfolders

content of nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
    <metadata minClientVersion="3.3.0">
        <id>NugetPackage</id>
        <version>1.0.0.0</version>
        <authors>some author</authors>
        <owners>some owner</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>description of pockage</description>
        <copyright>Copyright 2018</copyright>
        <contentFiles>
            <files include="**\*.*" buildAction="Content"/>
        </contentFiles>
    </metadata>
</package>

call nuget pack and the package is created.
Adding this package to a project with the new csproj format works fine.
Adding this package to a project with the old csproj format doesn't work.
Both use PackageReference.

Nuget.exe verbose log:
NuGet Version: 4.3.0.4406
Attempting to build package from 'testPackage.nuspec'.

Id: testPackage
Version: 1.0.0.0
Authors: Komax AG
Description: Test data for Database Administration Tool
Dependencies: None

Added file '[Content_Types].xml'.
Added file '_rels/.rels'.
Added file 'package/services/metadata/core-properties/0f0de1437e974b06b6c339e64c1477e2.psmdcp'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/CrimpModules.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/Machine.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/Prefeeder.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/PrintModules.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/Q1240.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/RingSensor.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/SealModules.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/WireChangeDetection.xml'.
Added file 'TestData/TopWin2/17.10/A530/MigrationMapping/WireStraightener.xml'.
Added file 'TestData/TopWin2/17.10/A530/TopWin2_Alpha530.kback'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/CrimpModules.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/Machine.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/Prefeeder.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/Q1240.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/SealModules.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/Splice.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/WireChangeDetection.xml'.
Added file 'TestData/TopWin2/17.10/A550/MigrationMapping/WireStraightener.xml'.
Added file 'TestData/TopWin2/17.10/A550/TopWin2_Alpha550.kback'.
Added file 'TestData/TopWin4/17.12/Alpha530/topwindata_emptyWithElectricEndPoints.mdf'.
Added file 'TestData/TopWin4/17.12/Alpha530/topwindata_emptyWithElectricEndPoints_log.ldf'.
Added file 'TestData/TopWin4/17.12/Alpha550/topwindata_emptyWithElectricEndPoints.mdf'.
Added file 'TestData/TopWin4/17.12/Alpha550/topwindata_emptyWithElectricEndPoints_log.ldf'.
Added file 'TestData/TopWin4/topwindata.bak'.
Added file 'testPackage.nuspec'.

Successfully created package '..\testPackage.1.0.0.nupkg'.

What am I doing wrong?
testPackage.zip

@rohit21agrawal
Copy link
Contributor

can you attach a repro project for old style csproj (PackageReference based) which does not work for you?

@rohit21agrawal rohit21agrawal added Area:ContentFiles PackageReference contentFiles folder WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Mar 16, 2018
@canhazcodez
Copy link
Author

Sorry for the delayed answer, I didn't have access to the work pc on the weekend.

I have attached a project that references the testpackage. The output says that the installation is done, but there is no change in project structure (no content added).

Cheers and thanks for the interest in helping me out :-)

OldProjectFormatWithPackageReference.zip

@canhazcodez
Copy link
Author

@rohit21agrawal do I have to remove the label (if so then how do I do it?) or is it enough that I answered the thread for it to not be waiting for customer anymore?

@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Mar 29, 2018

the best part about contentFile feature in NuGet is that the addition of content is done behind the scenes during build time . The content will be available to you when you need it.

If you modify your nuspec and set copyToOutput=true :

<files include="**\*.*" buildAction="Content" copyToOutput="true"/>

then it will also be copied to the build output folder on build. I verified this with your project and package

@nkolev92
Copy link
Member

Am i correct to interpret this as "Not a bug"?
Has the issue been resolved here?
@ElMaxxi @rohit21agrawal

@canhazcodez
Copy link
Author

canhazcodez commented Apr 16, 2018 via email

@rohit21agrawal
Copy link
Contributor

@ElMaxxi if it's not resolved, can you please reply to my earlier comment?

@canhazcodez
Copy link
Author

canhazcodez commented Apr 16, 2018 via email

@rohit21agrawal
Copy link
Contributor

So change the buildAction to Compile

@canhazcodez
Copy link
Author

canhazcodez commented Apr 16, 2018 via email

@nkolev92
Copy link
Member

@ElMaxxi
That should do it.

Simply reply whenever you have change to test it, no rush :)

@nkolev92
Copy link
Member

Hey,
@ElMaxxi Any updates?
Is this safe to close now?

@canhazcodez
Copy link
Author

So I changed the nuspec file buildAction to compile and then called "nuget pack". Then I added the .nuget package that was created to the aforementioned project and nothing happened. No files added or anything.

No to mention that I do not want to add files that will be compiled, I just want to add files as content to the project.

If you help me figure out how I can debug nuget locally, I will try to find the error myself.

@jainaashish
Copy link

@ElMaxxi Sorry for the confusion, if you just want to add files as Content then you can just set buildAction to Content. These files are added as linked file to the project, meaning they aren't directly copied into project folder but available to be consumed in your code. After you install this package check in obj/<projectName>.csproj.nuget.g.props file, all your files must be mentioned there as content.

You can also look at this sample - https://github.com/NuGet/Samples/tree/master/ContentFilesExample

@canhazcodez
Copy link
Author

@jainaashish Thanks for the answer. I have fiddled around with the example that you linked and I am experiencing some peculiar behavior. I remove the "authoring" package to the "consuming" project and it can't build (OK so far). I add the package that I created using the .ps1 script and now it builds. HOWEVER, inside visual studio I do NOT see the files anywhere in the solution explorer.
I have, then, created a new project (.net standard just to make sure it is using the new csproj format and then also a .net core console app) and add the same package (authoring from before) and visual studio now shows the files in the solution explorer.

@jainaashish
Copy link

HOWEVER, inside visual studio I do NOT see the files anywhere in the solution explorer.

Can you reload the solution and see if that shows th file then? And what's the content of obj/<projectName>.csproj.nuget.g.props file?

@nkolev92
Copy link
Member

nkolev92 commented Jun 7, 2018

In the old project format content files are not displayed in the UI.
There's a tracking issue for that - dotnet/project-system#3431

@canhazcodez
Copy link
Author

Alright guys, I was finally about to try a couple of things.
@nkolev92 it seems that I am experiencing the same issue as you described.
@jainaashish the files appear in the project.assets.json file but not in the UI, as nkolev92 mentioned.

I hadn't known about the UI issue and that is why I got really confused.

Thank you all so much for the help and for your input.

@nkolev92
Copy link
Member

Glad you figured it out @ElMaxxi
Thanks for closing the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:ContentFiles PackageReference contentFiles folder WaitingForCustomer Applied when a NuGet triage person needs more info from the OP
Projects
None yet
Development

No branches or pull requests

4 participants