nuspec contentFiles 未添加到项目中 [英] nuspec contentFiles not added to a project

查看:13
本文介绍了nuspec contentFiles 未添加到项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a web project (mvc5) with a project.json inside.

Also, I have a nuget package. Inside this package (besides the dll reference) I have some Content files (cshtml files, css, javascript etc).

There are 2 goals to achieve:

  • After installing the package to the project I want to get Content Files included to the project.
  • After Building the project I want nuget to restore the content files

The nuspec file:

<?xml version="1.0"?>
    <package>
      <metadata>
        /.../

        <dependencies>
            <group targetFramework="net461">
              /.../

           </group>
        </dependencies>
          <contentFiles>
        <files include="**/*.*" flatten="false" copyToOutput="false" buildAction="Content" /> 
      </contentFiles>
      </metadata>
      <files>
         /.../
    <file src="..srcContent***.*" target="contentFilesanyanyContent" /> 
    <file src="..srcViews***.*" target="contentFilesanyanyViews" /> 
      </files>
    </package>

Well, Visual Studio is adding nuget package with no issues. The reference is also included. But the content is always missing. The content files are not copied from the /packages/ folder and are not included to the project. The same is when I build the project - it just copies the dll and does not touch content files from the package at all.

It only works if I have copyToOutput="true", but all content goes to bin folder, of course.

The reason why I need to restore the content files is that the files from the nuget package are ignored by a tfs 'ignore file' (.tfignore). I don't want to have these content files to be a part of the web project in TFS. However, of course, TFS build server fails to build the project, because some content files are missing (the files from the package). So I want nuget on the build server to restore the content files before it stats building the project.

Any idea how to get this work if it is possible? Or maybe this is not possible and I must have content files to be included to the project?

解决方案

you could add a msbuild target to your package. in this target you can execute the nuget restore command...

example:

<?xml version="1.0"?>
<package >
    <metadata>
    <!-- ... -->
    </metadata>
    <files>
      <!-- Include your MSBuild target to uild -->
      <file src="buildmyNuGetRestoreTarget.targets" target="build" />
    </files>
</package>

see: https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package

这篇关于nuspec contentFiles 未添加到项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆