[英]How can I create a Nuget package as part of my CI process and when building locally?
我知道之前已經問過這個問題,但我找到的答案由於某些原因對我沒有用。
請讓我描述我的問題。
我正在使用Visual Studio 2012和TFS 2012
在我的組織中,我們有幾個應用程序,其中一些暴露共享DLL,我們希望將它們作為Nuget包發布在私有Nuget服務器中
所以在其中一個項目中,我將以下代碼添加到csproj文件中
<Target Name="AfterBuild">
<Exec ContinueOnError="false" WorkingDirectory="$(OutDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -Properties Configuration="$(Configuration)";Platform="$(Platform)"" />
</Target>
在與我的項目文件相同的級別,我有nuspec文件代表我的Nuget元數據,它看起來像:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Super dooper cool framework</releaseNotes>
<copyright>$copyright$</copyright>
<tags>Some My Company framework</tags>
</metadata>
</package>
這在本地非常好用,每次我構建我的項目時,它都會按照我想要的方式為我創建一個Nuget包。
但是在構建服務器上它不起作用,我嘗試了幾種組合,並且我一直收到同樣的錯誤:
"D:\Builds\23\someCompany\somebuilddefinition\Sources\.nuget\nuget.exe" pack "D:\Builds\23\someCompany\somebuilddefinition\Sources\NugetLibrary\NugetLibrary.csproj" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -Properties Configuration="Release";Platform="AnyCPU"
Attempting to build package from 'NugetLibrary.csproj'.
NuGet.CommandLineException: Unable to find 'D:\Builds\23\someCompany\somebuilddefinition\Sources\NugetLibrary\bin\Release\NugetLibrary.dll'. Make sure the project has been built.
at NuGet.Commands.ProjectFactory.BuildProject()
at NuGet.Commands.ProjectFactory.CreateBuilder(String basePath)
at NuGet.Commands.PackCommand.BuildFromProjectFile(String path)
at NuGet.Commands.PackCommand.BuildPackage(String path)
at NuGet.Commands.PackCommand.ExecuteCommand()
at NuGet.Commands.Command.Execute()
at NuGet.Program.Main(String[] args)
這是可以理解的,因為在構建服務器上,輸出路徑被覆蓋,它指向:
D:\Builds\23\someCompany\somebuilddefinition\Binaries
所以我嘗試了幾種組合,但我找不到一種方法來強制Nuget使用我的自定義路徑來查找構建過程生成的DLL。
這些是我到目前為止嘗試過的組合:
(基本上我使用了以下Nuget屬性: OutputDirectory
, BasePath
和Properties
)
BTW $(OutDir)
MSBuild屬性指向構建服務器上的正確文件夾
<Exec ContinueOnError="false" WorkingDirectory="$(OutDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -Properties Configuration="$(Configuration)";Platform="$(Platform)"" />
<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -BasePath "$(OutDir)" -OutputDirectory "$(OutDir)"" />
<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -OutputDirectory "$(OutDir)"" />
<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -BasePath "$(OutDir)" -OutputDirectory "$(OutDir)"" />
<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -BasePath "$(OutDir)" -OutputDirectory "$(OutDir)" -Properties Configuration="$(Configuration)";Platform="$(Platform)"" />
<Exec ContinueOnError="false" WorkingDirectory="$(OutDir)" Command=""$(SolutionDir).nuget\nuget.exe" pack "$(ProjectPath)" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes" />
我一直收到同樣的錯誤:
NuGet.CommandLineException: Unable to find 'D:\Builds\23\somecompany\somebuildserver\Sources\NugetLibrary\bin\Release\NugetLibrary.dll'. Make sure the project has been built.
那么Nuget只是忽略了BasePath
屬性? 為什么? 我錯過了什么?
看起來您可能會遇到http://nuget.codeplex.com/workitem/1486 。 基於對該問題的評論,看起來向您的pack命令添加-Properties OutDir=$(OutDir)
可能會修復它。
你可能想試試我的個人項目http://nuproj.codeplex.com/ 。 它允許通過MSBuild創建NuGet包。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.