NuGet Pack:忽略默认包括 [英] NuGet Pack: ignore default includes

查看:112
本文介绍了NuGet Pack:忽略默认包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是与我通常读到的相反的问题,即人们试图获取NuGet软件包中包含的文件.我正在尝试停止自动添加文件.

This is the opposite problem from what I usually read about, which is people trying to get files included in the NuGet package. I'm trying to stop file from being included automatically.

我正在创建预编译的MVC视图模板(使用RazorGenerator.Mvc),.less文件和JavaScript的库,以根据需要支持它们.想法是这些是进入我们所有站点的基本内容.

I'm creating a library of pre-compiled MVC view templates (using RazorGenerator.Mvc), .less files, and JavaScript to support these as needed. The idea is that these are basic things that go into all of our sites.

默认情况下,nuget pack包含项目中标记为构建操作:内容"的所有文件,这些文件将是任何新创建的视图,.less文件或脚本. 似乎没有其他方法可以替代此行为.此处的一个相关问题提出了<files>节点的解决方案在.nuspec中停止所有包含文件,但我想仅包含我选择的文件包含一些文件.

By default, nuget pack includes any files marked Build Action: Content in your project, which any newly-created view, .less file, or script would be. There seems to be no option to override this behavior. A related question here presented a solution of an empty <files> node in the .nuspec to stop all includes, but I want to include some files, just only the ones I choose.

现在,作为权宜之计,我可以尝试一下,将所有内容都明确地设置为内容(改为使用 None ),然后显式设置我处理和不处理的文件不想复制,我想使用.nuspec文件将它们复制到何处.但是,如果另一个开发人员(例如我将来的自己)走了而忘记了这一步,那么新添加的文件将被复制到程序包中,然后在下一次安装或更新期间复制到目标项目中.

Now, as a stopgap, I can go through, explicitly set everything not to be Content (using None instead), then explicitly setup which files I do and don't want copied and where I want them copied to using the .nuspec file. However, if another developer comes along, such as my future self, and forgets this step, then the newly-added files will be copied into the package, and then into the destination project during the next install or update.

我发现了 OctoPack ,并且一旦它检测到.nuspec中的<files>节点,默认情况下将不包含任何内容,但是我没有使用TeamCity的其他任何东西,而是重写了我的构建服务器脚本了解如何调用OctoPack而不是nuget pack并不是一个不错的选择. OctoPack也有局限性.依赖关系必须手动列出,.nuspec文件的替换令牌必须在命令行中传递(而不是从AssemblyInfo.cs中读取),而且似乎该工具并非旨在用于此用途-甚至说"OctoPack只应安装在要部署的项目上-这意味着控制台应用程序项目,Windows Service项目和ASP.NET Web应用程序.单元测试,类库和其他支持项目则不行被选中." ( OctoPack文档)

I found OctoPack, and that will including nothing by default as soon as it detects a <files> node in the .nuspec, but I'm not using anything else from TeamCity, and rewriting my build server scripts to understand how to invoke OctoPack instead of nuget pack doesn't strike me as a great option. OctoPack also has limitations; the dependencies have to be listed manually, the replacement tokens for the .nuspec file have to be passed in on command line (instead of read from AssemblyInfo.cs), and it just doesn't seem like the tool was intended for this use--they even say "OctoPack should only be installed on projects that you are going to deploy - that means the console application projects, Windows Service projects, and ASP.NET web applications. Unit tests, class libraries, and other supporting projects wouldn't be selected." (OctoPack Documentation)

我尝试的下一个选择是使用msbuildBeforeBuild事件期间简单地擦除Content组:

The next alternative I tried was using msbuild to simply wipe out the Content group during the BeforeBuild event:

<Target Name="BeforeBuild">
    <ItemGroup>
      <Content Remove="**\*.*" />
      <None Include="**\*.*" />
    </ItemGroup>
  <Message Text="Content files: @(Content)" Importance="High" />
</Target>

该消息验证内容组为空,但nuget pack似乎并不在意;它仍然包括所有文件.

The message verifies that the Content group is empty, but nuget pack doesn't seem to care; it still includes all the files anyway.

是否有人成功创建了这样的软件包,而无需手动标记所有构建操作:,也无需使用OctoPack?

Has anyone successfully created a package like this, without having to manually mark everything Build Action: None and without using OctoPack?

推荐答案

看来,如果您调用 nuget pack MyProject.nuspec (而不只是nuget pack,它将同时查找.csproj.nuspec),尽管仍然(例如使用OctoPack)仍然丢失令牌替换和自动依赖项,但是您可以获得所需的行为.因此,这不是一个完美的解决方案,就像--no-default-content一样,但是它可以很好地完成工作.

It seems that if you invoke nuget pack MyProject.nuspec (instead of just nuget pack, which will look for both the .csproj and .nuspec), you can get the desired behavior, although you still (like with OctoPack) lose token substitution and automatic dependencies. So it's not a perfect solution, which would be something like --no-default-content, but it gets the job done well enough.

nuget pack MyProject.nuspec -Properties version={XYZ}(构建服务器在其中填充XYZ)至少可以让我确保版本号也正确递增.例如,我可以在.nuspec

nuget pack MyProject.nuspec -Properties version={XYZ} (where XYZ is filled in by the build server) will at least let me make sure the version number is incremented correctly too. For example, I could set in the .nuspec

<version>1.1.0.$version$</version>,仅使用SVN修订版作为最后一部分.

<version>1.1.0.$version$</version> and just use SVN revision as the last part.

这篇关于NuGet Pack:忽略默认包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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