C# 在本地构建时,如何创建Nuget包作为CI过程的一部分?
我知道以前有人问过这个问题,但出于某种原因,我找到的答案对我不起作用 请让我描述一下我的问题 我正在使用Visual Studio 2012和TFS 2012 在我的组织中,我们有几个应用程序,其中一些公开共享DLL,我们希望将它们作为Nuget包发布到私有Nuget服务器中 因此,在其中一个项目中,我向csproj文件添加了以下代码 这是可以理解的,因为在构建服务器上,输出路径被覆盖,并且它指向:C# 在本地构建时,如何创建Nuget包作为CI过程的一部分?,c#,visual-studio-2012,msbuild,nuget,C#,Visual Studio 2012,Msbuild,Nuget,我知道以前有人问过这个问题,但出于某种原因,我找到的答案对我不起作用 请让我描述一下我的问题 我正在使用Visual Studio 2012和TFS 2012 在我的组织中,我们有几个应用程序,其中一些公开共享DLL,我们希望将它们作为Nuget包发布到私有Nuget服务器中 因此,在其中一个项目中,我向csproj文件添加了以下代码 这是可以理解的,因为在构建服务器上,输出路径被覆盖,并且它指向: D:\Builds\23\someCompany\somebuilddefinition\Bin
D:\Builds\23\someCompany\somebuilddefinition\Binaries
因此,我尝试了几种组合,但我找不到一种方法来强制Nuget使用我的自定义路径来查找由构建过程生成的DLL
以下是我迄今为止尝试过的组合:
(基本上,我使用过以下Nuget属性:OutputDirectory
、BasePath
和属性
)
顺便说一句,$(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)"" />
那么Nuget只是忽略了
BasePath
属性吗?为什么?我错过了什么?看起来你可能遇到了。根据对该问题的评论,似乎将-Properties OutDir=$(OutDir)
添加到pack命令可能会解决此问题。您可能想尝试一下我的个人项目。它允许通过MSBuild创建NuGet包。我的建议是将NuGet调用与目标csproj文件分离,并在构建核心sln后运行的单独MSBuild脚本中调用它。通过这种方式,您可以调用NuGet,直接传入nuspec文件,而不是让NuGet执行csproj文件魔术,我怀疑这就是问题所在。值得一提的是,我们在我的组织中这样做,而且效果很好。唯一的区别是我调用了PowerShell脚本来运行NuGet,但核心exe调用几乎相同。
"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
<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.