Skip to content

Packaging Content Files with dnu pack #651

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

Closed
dheerajkp opened this issue Jun 1, 2015 · 25 comments
Closed

Packaging Content Files with dnu pack #651

dheerajkp opened this issue Jun 1, 2015 · 25 comments

Comments

@dheerajkp
Copy link

I tried both content and contentFiles sections in the project.json, to include a content file that should go into the package. When I use dnu pack command, the content file doesn't seem to be packaged.

Please let me know if there is any recommended way to package content files.

@davidfowl
Copy link
Member

This does't work yet. Also dnx projects don't support importing content.

@sujitdmello
Copy link

How should apps package their configuration files?

@davidfowl
Copy link
Member

@sujitdmello Don't confuse dnu publish with dnu pack, you don't deploy application with dnu pack so that's not really a problem.

@Codenator81
Copy link

@davidfowl I future dnx going to support importing content? It is very useful when I need include views for example in project

@Codenator81
Copy link

@davidfowl is there any way run bower or git commands on package install?

@lszomoru
Copy link

@davidfowl on Jun7th you said that "dnu pack" does not support content files as well as dnx projects do not support importing content. Has anything changed since then? I am asking as I would like to create an ASP.NET Class library, include some contents (static files) into the package and use that package from an ASP.NET website. The purpose of the ASP.NET class library to separate my app into modules for code sharing/re-usability.

@joeaudette
Copy link

As far as I know currently you can include files into the generated nuget. In cloudscribe.Web.Navigation I am including views like this:

"packInclude": {
"content/": "content/**"

},
"content": [ "Views/Shared/.cshtml", "Views/Shared/Components/Navigation/.cshtml" ],

and I can see that the package does include the files, but nuget does NOT install the files into the consuming web app currently. So we are only half way there, we can get files into a nuget package but not get them out. I'm not sure if I need both packinclude and content but that is what I have at the moment and the files do get included.

My project is a navigation view component and I want to have it install some views and an xml file that is used for building the navigation tree, but currently this is not working as far as I know even though I am able to include the files in the nuget package. I do want people to be able to modify these files after they are installed. I'm also interested in whether I could have views compiled into my dll inside the nuget package that could be used if the files don't exist on disk in the web app. For now I have to tell people to install the views manually to try this navigation library.

@davidfowl
Copy link
Member

That's right, you can package things into packages but there's no support for getting content copied into the application. For RC2 we'll support the new NuGet declarative content pattern https://github.com/NuGet/Home/wiki/%5BSpec%5D-Content-v2-for-project.json. I'm not sure it'll work for the case you describe though. You may have to write something that locates views from within packages.

@joeaudette
Copy link

@davidfowl are you saying that in RC2 it will be possible to have the view .cshtml files installed into the web app? That would be good enough for me. Having some kind of fallback to pre-compiled views from within the class library would be a nice to have feature but as long as I can deliver working views my main needs would be met.

@lszomoru
Copy link

@joeaudette thanks for the pointer. I was able to get the files into the package! one approach to get your shared views out of the package could be to use the CombinedFileProvider which currently exists only in this pull request - aspnet/FileSystem#142. I was able to use it to combine the physical file provider with an embedded file provider.

unfortunately, this approach does not work for my client-side scripts and for that I would need the support to copy the contents from the package into the web app. @davidfowl, from the spec it is not clear to me whether this will be included in the RC2 functionality. btw, kudos to the team for still adding new functionality to ASP.NET5 so late in the game!

@Codenator81
Copy link

I start using ViewComponent and TagHelper as alternative for now which can be overwritten by user of package.

@lszomoru
Copy link

@Codenator81, does your approach solve the problem for client-side scripts stored in a package?

@Codenator81
Copy link

@lszomoru No this good for views only. Any way if scripts is not custom take it from Bower. You can try put it in Component Views as well but I don`t try )

@lszomoru
Copy link

@Codenator81, thank for the clarifications. I have considered the option to place the scripts in a Bower package but the challenge with that approach is that view/controllers would be in a NuGet package while the scripts would be in a Bower package. Apart from the fact that my scripts are custom, I would like to keep everything related to my module (views, controllers, scripts, etc.) in one place.

@Codenator81
Copy link

@lszomoru yes I need dthe same approach. Don't hesitate to inform if you find solutions.

@lszomoru
Copy link

@davidfowl, do you think that it would make sense to close this issue as it is scoped to dnu pack which seems to work as expected using packInclude and open a separate one to add the necessary functionality to dnu restore? Thanks!

@Codenator81
Copy link

For now issue not to pack content but get it fro NuGet

@lszomoru
Copy link

@Codenator81, I am not really sure I understand. Even if you would put the content in a package on NuGet dnu restore does not seem to import the content from the package into the project which is what we are all asking for here.

What is really interesting is that I have found a functional test DnuPackAdditionalFilesTests.cs which validates that additional files in the package so I am not sure if we are missing functionality or it is just a bug in dnu restore. Unfortunately I am having trouble running the functional test on my machine so I do not know what the outcome of the test is but I will keep trying.

@Codenator81
Copy link

@lszomoru
Copy link

lszomoru commented Dec 1, 2015

@Codenator81, thanks for sharing. That does look interesting.

I debugged the tests in DnuPackAdditionalFilesTests.cs and from what I can tell, the tests are geared towards making sure that dnu package is working as expected, and the correct files are included in the package itself. @davidfowl, can you please confirm that in RC2 functionality will be added so that dnu restore will import the contents of the package into the project folder enabling people to include static content? Thanks!

@resnyanskiy
Copy link

@davidfowl
I agree with @lszomoru. It would be great if such feature will arrive with RC2. May be there is a separate issue which people could use to track?

@lszomoru
Copy link

lszomoru commented Jan 5, 2016

based on a comment from aspnet/dnx#3141, dnu and nuget command line tools will merge which is great news since nuget restore already supports the functionality that we are asking for here. Fingers crossed the merger happens in the RC2 time frame. I could not find an issue to track the merger but I will continue to keep an eye on this label: https://github.com/aspnet/dnx/labels/Move%20to%20NuGet

@Northgates-Systems
Copy link

I am building a Class Library Package that contains Middlewares, Controllers, Views, TagHelpers, Js and Css files. I need to add the Controllers and Views under the user Project's Controllers and Views as well as to add a folder under wwwroot to put my css/js files. It would be wonderful to do it all within nuget instead of having one nuget and one github. The thing is adding/removing the nuget package needs to add/remove those specific folders and Files. I think if we can get the path to the project that installs the middleware and even better, if the installing/removing the package could call a method say called Installing(bool IsInstalling) where we could push when true and cleanup when false. Upon installing, I would also like to load a ReadMe Html into VS to explain the utility.

@tomasaschan
Copy link

I found a workaround that works for my specific use cases (at least so far), even though it doesn't address all cases brought up in this thread. I thought I'd share it here even if it's not a complete solution, since it might help other googlers who (like me) end up here looking for any way to include non-compiled files in a package.

dnu does support embedded resources, so you can do something like

{
    ...
    "resource": [
        "js/*",
        "css/*",
        "config/*.json"
    ],
    ...
}

in project.json and have all files matched embedded in the dll. That is, they won't be on the file system in the consuming project, but they'll be available through

using System.Reflection;

var resourceName = "Your.Assembly.Name.config.settings.json"
var stream = Assembly.GetAssembly(typeof(SomeTypeInYourAssembly)).GetManifestResourceStream(resourceName);
var reader = new StreamReader(stream);

// Read the contents of the file as with any other stream, e.g. as if opened from a file on disk

@shmuelie
Copy link

shmuelie commented May 6, 2016

I have created a workaround for Visual Studio on Windows.

First create the following PowerShell file in the root of the project and name it CopyContent.ps1

param(
    [string]$out
)

Get-Content -Raw .\project.json | ConvertFrom-Json | select -ExpandProperty contentFiles | copy -Destination $out

Then open the .xproj file for your project and add the following to the bottom of the <project> section:

<Target Name="ContentCopy" AfterTargets="CoreCompile">
    <Exec Command="powershell.exe $(ProjectDir)\CopyContent.ps1 -out $(OutputPath)\$(Configuration)\dnxcore50" />
  </Target>

(note: you might need to change the dnxcore50)

Then just add the files you want copied to the contentFiles section of the project.json and they will be copied!

ryanbrandenburg pushed a commit that referenced this issue Nov 20, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants