-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Comments
This does't work yet. Also dnx projects don't support importing content. |
How should apps package their configuration files? |
@sujitdmello Don't confuse |
@davidfowl I future dnx going to support importing content? It is very useful when I need include views for example in project |
@davidfowl is there any way run bower or git commands on package install? |
@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. |
As far as I know currently you can include files into the generated nuget. In cloudscribe.Web.Navigation I am including views like this:
}, 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. |
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. |
@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. |
@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! |
I start using ViewComponent and TagHelper as alternative for now which can be overwritten by user of package. |
@Codenator81, does your approach solve the problem for client-side scripts stored in a package? |
@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 ) |
@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. |
@lszomoru yes I need dthe same approach. Don't hesitate to inform if you find solutions. |
@davidfowl, do you think that it would make sense to close this issue as it is scoped to |
For now issue not to pack content but get it fro NuGet |
@Codenator81, I am not really sure I understand. Even if you would put the content in a package on NuGet 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 |
@lszomoru https://github.com/aspnet/NodeServices/blob/master/Microsoft.AspNet.AngularServices/AngularRenderer.cs |
@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 |
@davidfowl |
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 |
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. |
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.
in
|
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 param(
[string]$out
)
Get-Content -Raw .\project.json | ConvertFrom-Json | select -ExpandProperty contentFiles | copy -Destination $out Then open the <Target Name="ContentCopy" AfterTargets="CoreCompile">
<Exec Command="powershell.exe $(ProjectDir)\CopyContent.ps1 -out $(OutputPath)\$(Configuration)\dnxcore50" />
</Target> (note: you might need to change the Then just add the files you want copied to the |
… 4.0.30, because 4.0.40 is broken. Fixes #651
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.
The text was updated successfully, but these errors were encountered: