Avoiding XML Generation When Using nuget Package

I am creating a package for my build, but I do not want to include docs / *. Xml files in my nuget package. I tried the -Exclude switch of the pack command and the exclude property for the file section in the nuspec file to explicitly exclude these files. None of this worked. Therefore, every time I create my nuget package and then test it by installing it in the target project, it always adds a document folder with all xml files. How can I avoid the fact that xml files are included in the nuget package? Any help would be greatly appreciated.

+2
nuget nuget-package
source share
3 answers

Thanks, Matt, I'm already doing what you talked about, but it seems to me that Nuget does some other things by agreement. Even if I use exclude the same way you said, the document folder is included. I solved the problem by creating a nuspec file with the -a switch (I used my .csproj file). I also had to copy the dll file to a folder outside my solutions folder. Thus, everything worked fine and as expected.

In any case, your answer is correct, but in my scenario it did not work. Not sure if this is by design. Here is my last msbuild file that I use to create the package. Hopefully Nuget will add more switches to the spec command soon, so we don’t have to change the nuspec file so much.

<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> 

 <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/> <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/> <Target Name="NugetPackage" DependsOnTargets="PackageClean;BuildNugetPackageMyAssembly"> 

 <Target Name="PackageClean"> <RemoveDir Directories ="NugetPkgs\$(Configuration)" ContinueOnError ="true"/> 

 <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
source share

To exclude all .xml files, you must use the ** \ * template. xml. I assume that you are using * .xml, which will not work.

To exclude all .xml files, you can use the nuget command line, similar to the following:

 nuget.exe pack MyPackage.nuspec -Exclude **\*.xml 

If you only need to exclude .xml files in the docs directory, you can use the nuget command line, similar to the following:

 nuget.exe package MyPackage.nuspec -Exclude **\docs\*.xml 

Wildcards seem to work relative to the folder where your .nuspec file is located. So, if you have a .xml file in the docs subfolder relative to the .nuspec file, then you need to work with the template if docs * .xml should work too.

0
source share

Another thing I can think of is

  • Create a nuspec file and edit it. this needs to be done only once (you can also check). Any reasons why you are editing the nuspec file when you create it?
  • use files in nuspec file to copy files to destination folders

<files> <src file = "bin \ Debug \ *. dll" target = "lib" / "> <src =" bin \ Debug \ *. pdb file "target =" lib "/"> <src = file tools \ * \. * "exclude =" * \. log "/"> </ files>

3. The pack command can be executed at build time.

More information about the files can be found here http://docs.nuget.org/docs/reference/nuspec-reference

0
source share

All Articles