【发布时间】:2013-05-22 22:27:35
【问题描述】:
我知道以前有人问过这个问题,但由于某种原因,我找到的答案对我不起作用。
请让我描述一下我的问题。
我正在使用 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>
在与我的项目文件相同的级别上,我有一个代表我的 Nuget 元数据的 nuspec 文件,它看起来像:
<?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)
顺便说一句,$(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 属性吗?为什么?我错过了什么?
【问题讨论】:
-
我的建议是将 NuGet 调用与目标 csproj 文件分开,并在构建核心 sln 后运行的单独 MSBuild 脚本中调用它。这样您就可以调用 NuGet,直接传入 nuspec 文件,而不是让 nuget 执行它的 csproj 文件魔术,我怀疑这是问题所在。对于它的价值,我们在我的组织中执行此操作,并且运行良好。唯一的区别是我调用 PowerShell 脚本来运行 NuGet,但核心 exe 调用几乎相同。
标签: c# visual-studio-2012 msbuild nuget