アセンブリ用のパッケージを作成していますが、nugetパッケージにdocs/*。xmlファイルを含めたくありません。packコマンドの-Excludeスイッチとnuspecファイルのfilesセクションのexcludeプロパティを試して、これらのファイルを明示的に除外しました。これらはどれも機能しませんでした。したがって、nugetパッケージを生成し、それをターゲットプロジェクトにインストールしてテストするたびに、すべてのxmlファイルを含むdocsフォルダーが常に追加されます。xmlファイルがnugetパッケージに含まれていることを回避するにはどうすればよいですか?どんな助けでも大歓迎です。
3 に答える
すべての.xmlファイルを除外するには、**\*。xmlワイルドカードを使用する必要があります。動作しない*.xmlを使用していると思います。
すべての.xmlファイルを除外するには、次のようなnugetコマンドラインを使用できます。
nuget.exe pack MyPackage.nuspec -Exclude **\*.xml
docsディレクトリ内の.xmlファイルのみを除外する必要がある場合は、次のようなnugetコマンドラインを使用できます。
nuget.exe package MyPackage.nuspec -Exclude **\docs\*.xml
ワイルドカードは、.nuspecファイルが含まれているフォルダーに関連して機能するようです。したがって、.nuspecファイルに関連するdocsサブフォルダーに.xmlファイルがある場合は、docs*.xmlも機能するはずです。
マットに感謝します。私はすでにあなたが言ったことをやっていますが、Nugetは慣例により他のことをしているようです。あなたが言ったように除外を使用しても、docsフォルダが含まれています。-aスイッチを使用してnuspecファイルを生成することで問題を解決しました(.csprojファイルを使用していました)。また、.dllファイルをソリューションのフォルダー外のフォルダーにコピーする必要がありました。このようにして、すべてが正常に機能し、期待どおりに機能しました。
とにかくあなたの答えは正確ですが、私のシナリオではうまくいきませんでした。これが仕様によるものかどうかはわかりません。これが、パッケージの生成に現在使用している最後のmsbuildファイルです。うまくいけば、Nugetはすぐにspecコマンドにスイッチを追加するので、後でnuspecファイルをそれほど変更する必要はありません。
<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=""$(NuGetExePath)" spec -a "$(OutputPathCore)\lib\net40\My.Assembly.dll"" />
<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=""$(NuGetExePath)" pack My.Assembly.nuspec -OutputDirectory "$(OutputPathCore)\Package" -NoPackageAnalysis" />
<Delete Files ="My.Assembly.nuspec" />
私が考えることができるもう一つのことは
- nuspecファイルを作成して編集します。これは1回だけ実行する必要があります(チェックインすることもできます)。ビルド中にnuspecファイルを編集している理由は何ですか?
- nuspecファイルのfiles要素を使用して、ファイルを宛先フォルダーにコピーします
<files> <file src = "bin \ Debug\*。dll"target= "lib" /> <file src = "bin \ Debug\*。pdb"target= "lib" /> <file src = "tools \ * \。*"exclude=" * \ .log "/> </ files>
3. packコマンドは、ビルド時に実行したままにすることができます。
ファイルの詳細については、http://docs.nuget.org/docs/reference/nuspec-referenceを参照してください。