本文將簡單介紹在生產環境使用Nuget
關於Nuget
官方提供的使用文檔比較豐富
要在實際生產環境使用它來做打包和包管理
nfig的繼承和解決方案中的識別
比如
nuget updatexx
它做的事只是對比包得版本是否有更新並更新之
nuget install nfig
只能指定具體的config文件
和build的集成度
類似上面一點
nuget雖然提供
repository的安裝位置不可配置
默認情況下package的安裝目錄是在
這個問題在它的官方已經有人在問了
以下提供一些解決上述問題或實際應用時的一些方法
下述范例所在目錄結構
/ops-base/feeds/是自己hosting的一個nuget feed(-packages/hosting-your-own-nuget-feeds)
創建包描述文件:
<?xmlversionxmlversion="1.0"?>
<packagexmlnspackagexmlns="">
<metadata>
<id>Package.Castle</id>
<version>2.1</version>
<title>Castle</title>
<authors>Castle</authors>
<owners/>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
IOC容器
</description>
<copyright>2011</copyright>
<language>zh-CN</language> </metadata> <files>
<filesrcfilesrc="CastleCastle.Core.dll"target="lib et40Castle.Core.dll"/>
<filesrcfilesrc="CastleCastle.Core.xml"target="lib et40Castle.Core.xml"/>
<filesrcfilesrc="CastleCastle.DynamicProxy2.dll"target="lib et40Castle.DynamicProxy2.dll"/>
<filesrcfilesrc="CastleCastle.DynamicProxy2.xml"target="lib et40Castle.DynamicProxy2.xml"/>
<filesrcfilesrc="CastleCastle.MicroKernel.dll"target="lib et40Castle.MicroKernel.dll"/>
<filesrcfilesrc="CastleCastle.MicroKernel.xml"target="lib et40Castle.MicroKernel.xml"/>
<filesrcfilesrc="CastleCastle.Windsor.dll"target="lib et40Castle.Windsor.dll"/>
<filesrcfilesrc="CastleCastle.Windsor.xml"target="lib et40Castle.Windsor.xml"/>
</files>
</package>
批量打包和發布到feeds,pack.bat腳本如下:
echo off
mkdir assemblypackages
echo pack
forfiles /p assembly /m *.nuspec /c "cmd /c .. ools uget pack @file-outputdirectory packages"
echo push
forfiles /p assemblypackages /m *.nupkg /c "cmd /c .... ools uget push @file-s&//ops-base/feeds/hello1234"
echo on
批量安裝和更新本地package,nuget.install.bat腳本如下:
echo off
echo install
forfiles /s /m nfig /c "cmd /c %1 uget install @file -o %2"
echo update
forfiles /s /m nfig /c "cmd /c %1 uget update @file -source&//ops-base/feeds/nuget"
echo on
然後使用NANT然完成構建過程,nant.build部分內容如下:
<?xmlversionxmlversion="1.0"?>
<projectnameprojectname="infrastructure"default="build">
<propertynamepropertyname="nfig"value="release"dynamic="true"/>
<!--path-->
<propertynamepropertyname="dir"value="."/>
<propertynamepropertyname="dir.tools"value=". ools"/>
<propertynamepropertyname="build.base"value="build${nfig}"/>
<propertynamepropertyname="build.absolutepath"value="${path::get-full-path(build.base)}"/>
<!--msbuild-->10: <propertynamepropertyname="msbuild"value="C:WINDOWSMicrosoft.NETFrameworkv4.0.30319MSBuild.exe"/>
<propertynamepropertyname="nfig"value="Debug"dynamic="true"/>
<iftestiftest="${nfig=='Release'}">
<propertynamepropertyname="nfig"value="Release"/>
</if>
<propertynamepropertyname="msbuild.params"
value="/t:rebuild
/p:Configuration=${nfig}
/p:AllowUnsafeBlocks=true
/t:ResolveReferences" />
<propertynamepropertyname="msbuild.params.weboutput"value="/t:_CopyWebApplication /p:WebProjectOutputDir=${build.absolutepath}"/>
<propertynamepropertyname="msbuild.params.output"value="/p:OutputPath=${build.absolutepath}"/>
<!--nuget-->
<propertynamepropertyname="nuget"value="${path::get-full-path(dir.tools)}"/>
<propertynamepropertyname="nuget.packages"value="${dir}packages"/>
<propertynamepropertyname="nuget.install"value="${dir} uget.install.bat"/>
<propertynamepropertyname="nuget.params.install"value="${nuget} ${path::get-full-path(nuget.packages)}"/>
<!--build infrastructure-->
<targetnametargetname="base"description="Infrastructure">
<execprogramexecprogram="${nuget.install}"commandline="${nuget.params.install}"workingdir="${dir}"/>
<execprogramexecprogram="${msbuild}"
commandline="${msbuild.params} ${msbuild.params.output}" workingdir="${dir}Infrastructure\"/>
</target>
</project>
上述nant腳本中,target=base的構建目標就是要構建的項目了,首先執行nuget.install.bat腳本更新本地packages,然後執行msbuild
然後運行下述腳本執行構建:
. ools antin ant base
到這裡就完成了將nuget投入項目環境使用的相關准備工作:)
From:http://tw.wingwit.com/Article/program/net/201311/13014.html