首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何避免在使用nuget pack时生成xml文档

如何避免在使用nuget pack时生成xml文档
EN

Stack Overflow用户
提问于 2012-11-25 10:50:53
回答 3查看 2.1K关注 0票数 2

我正在为我的程序集创建包,但是我不想在我的nuget包中包含docs/*.xml文件。我尝试过使用pack命令的-Exclude开关和nuspec文件中文件部分的排除属性来明确排除这些文件。这些都不管用。因此,每次我生成nuget包,然后通过在目标项目中安装它来测试它时,它总是添加一个包含所有xml文件的docs文件夹。如何避免xml文件包含在nuget包中?任何帮助都将不胜感激。

EN

Stack Overflow用户

回答已采纳

发布于 2012-11-26 16:30:45

谢谢你,Matt,我已经在做你提到的事情了,但是在我看来Nuget按照惯例做了一些其他的事情。即使我像您所说的那样使用排除,docs文件夹也会被包括在内。我通过使用-a开关(我使用我的.csproj文件)生成nuspec文件解决了这个问题。我还必须将.dll文件复制到我的解决方案文件夹之外的文件夹中。通过这种方式,一切都工作得很好,并且如预期的那样。

无论如何,你的答案是准确的,但在我的场景中,它不起作用。不确定这是否是设计好的。这是我的最后一个msbuild文件,我目前正在使用它来生成这个包。希望Nuget很快会在spec命令中添加更多的开关,这样我们以后就不需要修改nuspec文件了。

代码语言:javascript
复制
<Project DefaultTargets="NugetPackage" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  

<PropertyGroup>
 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
 <OutputPathCore>NugetPkgs\$(Configuration)\My.Assembly</OutputPathCore>
 <NuGetExePath>assets\nuget.exe</NuGetExePath>     

代码语言:javascript
复制
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>

<Target Name="NugetPackage" DependsOnTargets="PackageClean;BuildNugetPackageMyAssembly">   

代码语言:javascript
复制
<Target Name="PackageClean">  
<RemoveDir Directories ="NugetPkgs\$(Configuration)" ContinueOnError ="true"/>  

代码语言:javascript
复制
<Target Name="BuildNugetPackageMyAssembly">   
   <MakeDir Directories="$(OutputPathCore)" />
   <MakeDir Directories="$(OutputPathCore)\Package" />
   <MakeDir Directories="$(OutputPathCore)\lib\net40" />
   <MakeDir Directories="$(OutputPathCore)\lib\net20" />      
   <MakeDir Directories="$(OutputPathCore)\lib\net20-cf" />   

   <Copy
       DestinationFolder="$(OutputPathCore)\lib\net40" 
       SourceFiles="Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll" />

    <Copy
       DestinationFolder="$(OutputPathCore)\lib\net20" 
       SourceFiles="VS2008\Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll" />

    <Copy
       DestinationFolder="$(OutputPathCore)\lib\net20-cf" 
       SourceFiles="VS2008\Source\My.Assembly.CF\bin\$(Configuration)\My.Assembly.CF.dll" />

   <Copy DestinationFolder="$(OutputPathCore)\content" SourceFiles="CHANGES" />

   <Copy SourceFiles="Release Notes.txt" DestinationFiles="$(OutputPathCore)\Readme.txt" />

   <Exec Command="&quot;$(NuGetExePath)&quot; spec -a  &quot;$(OutputPathCore)\lib\net40\My.Assembly.dll&quot;" />              

    <XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/licenseUrl" Value="http://someurl" />          
    <XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/projectUrl" Value="http://someurl" />          
    <XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/iconUrl" Value="http://somenice.png" />            
    <XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/tags" Value="My.Assembly" />           
    <XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/releaseNotes" Value="Review readme.txt for details." />  

<ItemGroup>      
  <file Include="Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll"/>
  <file Include="VS2008\Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll"/>    
  <file Include="$(OutputPathCore)\Readme.txt"/>
</ItemGroup>

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" File="My.Assembly.nuspec" Element="dependencies" XPath="//package/metadata/dependencies" />

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddElement" File="My.Assembly.nuspec" Key="" Value="" Element="files" XPath="//package" InsertAfterXPath="//package" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddElement" File="My.Assembly.nuspec" Key="src" Value="%(file.Identity)" Element="file" XPath="//package/files" />

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddAttribute" File="My.Assembly.nuspec" XPath="//package/files/*[1]"  Key="target" Value="lib\net40" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddAttribute" File="My.Assembly.nuspec" XPath="//package/files/*[2]"  Key="target" Value="lib\net20" />  
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddAttribute" File="My.Assembly.nuspec" XPath="//package/files/*[3]"  Key="target" Value=""/>


<Exec Command="&quot;$(NuGetExePath)&quot; pack My.Assembly.nuspec -OutputDirectory &quot;$(OutputPathCore)\Package&quot; -NoPackageAnalysis" />

<Delete Files ="My.Assembly.nuspec" /> 

票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13547853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档