问题描述
我创建了npm包,其中包含js和css文件,类似于引导程序作为文件夹结构.我想为.Net mvc Web应用程序提供相同的程序包,所以我从构建输出中创建了 .nuspec
文件,并指定了 files
并创建了Nuget程序包.Nuget和NPM软件包都很好用.
现在,我想为点网核心项目发布相同的软件包.当我在点网核心Web应用程序中安装相同的Nuget软件包时,它已成功安装,但未将静态文件复制到项目文件夹中.
如何为点网核心应用程序创建/修复静态文件块块.我不想创建.net核心项目来运送静态文件.如果我还可以为点网核心应用程序添加一些配置文件(如 .nuspec
),那就太好了.
我已经搜索过但无法获得任何帮助,因此任何建议或参考都将适用.
myproject.nuspec
<?xml version ="1.0"?><包装><元数据>< id> MyPackage</id>< version> 1.0.1</version>< title> MyProject</title>< authors> Me</authors>< owners> Me</owners>< projectUrl>一些网址...</projectUrl>< requireLicenseAcceptance> false</requireLicenseAcceptance>< description>这类似于引导程序</description><版权>版权2020</copyright><标签></标签><依赖关系>< dependency id =" jQuery"版本="[3.0.0,4.0.0)"/></dependencies></元数据><文件>< file src ="dist \ css \ ** \ *.*"target =" content \ Content \ css"/>< file src =" dist \ fonts \ ** \ *.*"target =" content \ Content \ fonts"/>< file src =" dist \ js \ mypackage.js"target =" content \ Scripts"/>< file src ="dist \ images \ ** \ *.*"target =" content \ Content \ Images"/></files></package>
更新:我尝试了@thatguy在下面给出的解决方案,它确实将文件复制到了适当的文件夹中.我可以在Visual Studio中看到它们.但是,新创建的文件和文件夹上带有箭头符号,而其他文件则没有.我尝试在页面代码中包含CSS,但找不到新创建的文件.
此箭头的含义以及为什么找不到文件?
您应使用
2),然后将其添加到其中:
< Project><目标名称="CopyFilesToProject";BeforeTargets ="Build"<消息文本=将CSS文件复制到项目中"/>< ItemGroup>< SourceScripts Include =" $(MSBuildThisFileDirectory).. \ .. \ content \ ** \ *.*"/>//来自nuget包的文件</ItemGroup><复制SourceFiles ="@@(SourceScripts)"DestinationFiles ="@(SourceScripts->'$(MSBuildProjectDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"/></Target></Project>
3)更改为使用此 nusepc 文件:
<?xml version ="1.0"?><包装><元数据>< id> MyPackage</id>< version> 1.0.1</version>< title> MyProject</title>< authors> Me</authors>< owners> Me</owners>< projectUrl>一些网址...</projectUrl>< requireLicenseAcceptance> false</requireLicenseAcceptance>< description>这类似于引导程序</description><版权>版权2020</copyright><标签></标签><依赖关系>< dependency id =" jQuery"版本="[3.0.0,4.0.0)"/></dependencies></元数据><文件>< file src ="dist \ css \ ** \ *.*"target =" content \ Content \ css"/>< file src =" dist \ fonts \ ** \ *.*"target =" content \ Content \ fonts"/>< file src =" dist \ js \ mypackage.js"target =" content \ Scripts"/>< file src ="dist \ images \ ** \ *.*"target =" content \ Content \ Images"/>< file src =" build \ MyPackage.props"target ="build"/></files></package>
4)重新打包项目 MyPackage ,然后首先在主项目中首先卸载旧的nuget软件包 MyPackage .
然后,先清理nuget缓存,或删除 C:\ Users \ xxx(当前用户)\.nuget \ packages
下的所有缓存.
此后,安装新版本 MyPackage ,然后先构建您的项目,然后您会看到文件已复制到主项目下
此外,还有以及.
=================================
更新1
如果仅要将这些文件复制到 Net Core 项目中,则应放弃使用 nupkg
中的 content 节点.安装软件包时,它将自动将文件复制到NET Framework主项目中.
相反,您可以将这些文件放在 nupkg 的另一个名为 resource 的文件夹下.
您可以按照我的步骤进行操作
1)将 MyPackage.props
文件更改为:
< Project><目标名称="CopyFilesToProject";BeforeTargets ="Build"<消息文本=将CSS文件复制到项目中"/>< ItemGroup>< SourceScripts Include =" $(MSBuildThisFileDirectory).. \ .. \ resource \ ** \ *.*"/>//来自nuget包的文件</ItemGroup><复制SourceFiles ="@@(SourceScripts)"DestinationFiles ="@(SourceScripts->'$(MSBuildProjectDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"/></Target></Project>
2)将 xxx.nuspec
文件更改为:
<?xml version ="1.0"?><包装><元数据>< id> MyPackage</id>< version> 1.0.1</version>< title> MyProject</title>< authors> Me</authors>< owners> Me</owners>< projectUrl>一些网址...</projectUrl>< requireLicenseAcceptance> false</requireLicenseAcceptance>< description>这类似于引导程序</description><版权>版权2020</copyright><标签></标签><依赖关系>< dependency id =" jQuery"版本="[3.0.0,4.0.0)"/></dependencies></元数据><文件>< file src ="dist \ css \ ** \ *.*"target ="resource \ Content \ css"/>< file src =" dist \ fonts \ ** \ *.*"target =" resource \ Content \ fonts"/>< file src =" dist \ js \ mypackage.js"target ="resource \ Scripts"/>< file src ="dist \ images \ ** \ *.*"target =" resource \ Content \ Images"/>< file src =" build \ MyPackage.props"target ="build"/></files></package>
3),然后重新打包项目并安装新的项目,然后再清洁它.
I have created npm package which has js and css files just similar to bootstrap as folder structure. I want to ship same package for .Net mvc web applications so I created .nuspec
file specifying files
from build output and created Nuget package. Both the Nuget and NPM package working great.
Now I want to publish same package for dot net core project. When I install same Nuget package in dot net core web application it installed successfully but does not copied static files to project folders.
How to create/fix nugget package of static files for dot net core application. I don't want to create .net core project to ship static files. It would be great if I could add some configuration file like .nuspec
for dot net core application as well.
I have searched but not able to get any help in regards, So any suggestion or reference would be appriciated.
myproject.nuspec
<?xml version="1.0"?>
<package >
<metadata>
<id>MyPackage</id>
<version>1.0.1</version>
<title>MyProject</title>
<authors>Me</authors>
<owners>Me</owners>
<projectUrl>some url...</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is similar to bootstrap</description>
<copyright>Copyright 2020</copyright>
<tags></tags>
<dependencies>
<dependency id="jQuery" version="[3.0.0, 4.0.0)" />
</dependencies>
</metadata>
<files>
<file src="dist\css\**\*.*" target="content\Content\css" />
<file src="dist\fonts\**\*.*" target="content\Content\fonts" />
<file src="dist\js\mypackage.js" target="content\Scripts" />
<file src="dist\images\**\*.*" target="content\Content\Images" />
</files>
</package>
Update : I tried solution given below by @thatguy it does copied the files in appropriate folders. I can see those in Visual Studio. But that newly created files and folder has arrow symbol on it while other files does not. I tried including css in page code but it does not found the newly created files.
What this arrow means and why its not finding the files ?
You should use <package_id>.props file.
1) create a folder in your MyPackage called build
and then add a file called MyPackage.props
file in it.
2) Then add these in it:
<Project>
<Target Name="CopyFilesToProject" BeforeTargets="Build">
<Message Text="Copy css files to project" />
<ItemGroup>
<SourceScripts Include="$(MSBuildThisFileDirectory)..\..\content\**\*.* "/> //file from the nuget package
</ItemGroup>
<Copy
SourceFiles="@(SourceScripts)"
DestinationFiles="@(SourceScripts -> '$(MSBuildProjectDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
</Project>
3) change to use this nusepc file:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyPackage</id>
<version>1.0.1</version>
<title>MyProject</title>
<authors>Me</authors>
<owners>Me</owners>
<projectUrl>some url...</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is similar to bootstrap</description>
<copyright>Copyright 2020</copyright>
<tags></tags>
<dependencies>
<dependency id="jQuery" version="[3.0.0, 4.0.0)" />
</dependencies>
</metadata>
<files>
<file src="dist\css\**\*.*" target="content\Content\css" />
<file src="dist\fonts\**\*.*" target="content\Content\fonts" />
<file src="dist\js\mypackage.js" target="content\Scripts" />
<file src="dist\images\**\*.*" target="content\Content\Images" />
<file src="build\MyPackage.props" target="build" />
</files>
</package>
4) repack your project MyPackage and then first uninstall the old nuget package MyPackage first in your main project.
Then, clean nuget caches first or delete all caches under C:\Users\xxx(current user)\.nuget\packages
.
After that, install the new version MyPackage and then build your project first and you can see the files be copied under the main project.
In addition, there is a similar issue about your request and also this one.
==================================
Update 1
If you want these files only be copied on Net Core projects, you should abandon using content node in nupkg
. It will automatically copy files into the NET Framework main project when you install the package.
Instead, you could put these files under a different folder called resource of the nupkg.
You could follow my steps:
1) change MyPackage.props
file to:
<Project>
<Target Name="CopyFilesToProject" BeforeTargets="Build">
<Message Text="Copy css files to project" />
<ItemGroup>
<SourceScripts Include="$(MSBuildThisFileDirectory)..\..\resource\**\*.* "/> //file from the nuget package
</ItemGroup>
<Copy
SourceFiles="@(SourceScripts)"
DestinationFiles="@(SourceScripts -> '$(MSBuildProjectDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
</Project>
2) change xxx.nuspec
file to:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyPackage</id>
<version>1.0.1</version>
<title>MyProject</title>
<authors>Me</authors>
<owners>Me</owners>
<projectUrl>some url...</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is similar to bootstrap</description>
<copyright>Copyright 2020</copyright>
<tags></tags>
<dependencies>
<dependency id="jQuery" version="[3.0.0, 4.0.0)" />
</dependencies>
</metadata>
<files>
<file src="dist\css\**\*.*" target="resource\Content\css" />
<file src="dist\fonts\**\*.*" target="resource\Content\fonts" />
<file src="dist\js\mypackage.js" target="resource\Scripts" />
<file src="dist\images\**\*.*" target="resource\Content\Images" />
<file src="build\MyPackage.props" target="build" />
</files>
</package>
3) then repack your project and install the new one, before it, you should clean nuget caches first.
这篇关于从静态文件为点网核心项目创建Nuget包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!