Reputation: 560
I'm not able to copy the content static files in my .Net core web application project that I added when creating the nuget package using nuget package explorer. Same thing get copied correctly in .Net framework project template but not in .net core template. I'm using VS 2015 update 3.Am i Missing something here? Any help would be greatly appreciated.
Below is my snapshot of content file structure.
Upvotes: 13
Views: 6406
Reputation: 6658
It seems it is still not supported. Only way to "hack" it is with MSBuild Targets and Build events.
According to this documentation:
build
MSBuild .targets and .props files Automatically inserted into the project file or project.lock.json (NuGet 3.x+).
So to make it work with any file, e.g.: "config.xml" as Nuget Static Content:
<file src="config.xml" target="contentFiles\any\any\config.xml" />
<file src="XY.targets" target="build"/>
Content of the XY.targets file
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ContentFilesPath>$(MSBuildThisFileDirectory)..\contentFiles\any\any\</ContentFilesPath>
</PropertyGroup>
<Target Name="CopyConfigs" BeforeTargets="PreBuildEvent">
<Copy SourceFiles="$(ContentFilesPath)\config.xml" DestinationFiles="$(ProjectDir)config.xml" SkipUnchangedFiles="true" Condition="!Exists('$(ProjectDir)config.xml')"></Copy>
</Target>
</Project>
After packaging and installing the Nuget this MSBuild Target will be part of the Cached package and will run on each build (currently before build).
Issues with this solution:
Unfortunately this is the best solution for now.
Upvotes: 6
Reputation: 694
Some public nuget packages (e.g. https://www.nuget.org/packages/NUnit3TestAdapter/3.10.0 or https://www.nuget.org/packages/Selenium.WebDriver.ChromeDriver/) can copy files. I've tried to investigate it (https://github.com/nunit/nunit3-vs-adapter and https://github.com/jsakamoto/nupkg-selenium-webdriver-chromedriver). But it seems, they have implemented very tricky workaround
Upvotes: 0
Reputation: 2380
After reading this post I came up with a work around. I created a .Net assembly project and completely emptied it out of all content. Then I moved the project into the same directory as the project for the .Net Core Web application. Instead of adding the NuGet package reference from the web application, I add it from the .Net assembly project. All of the files are correctly copied into the directory and are automatically added to the web project, since they share the same directory. This solution feels very dirty, but it is allowing me to manage static files with a NuGet package for a .Net Core Web project.
Upvotes: -3
Reputation: 556
There is a nuget blog post about this, and it just isn't supported at this time.
Supported Project Types
This feature is only for packages that will be installed to projects that are managed using a project.json file. Currently only two projects types are managed by a project.json.
- UWP apps
- Portable class libraries
The contentFiles option is not available for other project types.
It's really a pity this basic functionality has been excluded from the .net Core projects. Especially because PCL is supported, which is a subset of a .net Core project.
There are quite some issues on GitHub about this, and it's very unclear whether or not this feature is coming back any time soon.
Upvotes: 10