Nuget真是霸道啊。。。

我有这么个需求:

项目里想使用Common.Logging来输出log,但并不想固定的依赖log4net或者NLog之类的,所以我不能直接install log4net之类的package。但是运行时当然又需要,所以我要写个build脚本,整体build完了之后把log4net.dll之类的copy到debug下面。

于是问题就来了:我的所有project都没有依赖log4net,所以packages目录下自然就没有log4net.1.2.10咯,那我copy的时候source是啥?

首先想到的自然是Nuget从1.6开始提供的package restore功能,反正我已经自己写脚本了,调用一下NuGet.targets不就好了?

事实证明我图样图森破了。。。 打开NuGet.targets

 

<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>

 

为毛写死了不许自定义啊。。。没关系,咱改了它

<PackagesConfig  Condition="$(PackagesConfig) == ''">$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>

之后在我的脚本里添加如下内容

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Buid" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>    
    <RestorePackages>true</RestorePackages>
    <PackagesConfig>$([System.IO.Path]::Combine($(MSBuildProjectDirectory), "MyComany.MyProduct.MySolution.Packages.config"))</PackagesConfig>
  </PropertyGroup>

  <Import Project="..\.nuget\nuget.targets" />

  <!--Build All-->
  <Target Name="Buid">
    <CallTarget Targets="RestorePackages"/>
  </Target>
</Project>

结果一运行,报错说我的"MyComany.MyProduct.MySolution.Packages.config"找不到。

我检查了好几遍路径都没错啊~~~结果把文件重命名为packages.config,成功了。。。

最后看了一下帮助(nuget help install)

usage: NuGet install packageId|pathToPackagesConfig [options]

Installs a package using the specified sources. If no sources are specified, all
 sources defined in %AppData%\NuGet\NuGet.config are used.  If NuGet.config spec
ifies no sources, uses the default NuGet feed.

     Specify the id and optionally the version of the package to install. If a
     path to a packages.config file is used instead of an id, all the packages
     it contains are installed.

你妹啊!为啥只认packages.config啊!


posted @ 2012-05-04 15:21  jiaxingseng  阅读(727)  评论(1编辑  收藏  举报