搭建自己的NuGet服务器以及在VS中自动生成NuGet包

1 篇文章 0 订阅
关于NuGet的介绍已经很多,可以参考下面的:
NuGet学习笔记(1)——初识NuGet及快速安装使用  http://kb.cnblogs.com/page/143190/
NuGet学习笔记(2)——使用图形化界面打包自己的类库  http://kb.cnblogs.com/page/143191/
NuGet学习笔记(3)——搭建属于自己的NuGet服务器   http://kb.cnblogs.com/page/143192/

上面的文章介绍了搭建Web版本的NuGet服务器以及用图形化的方式生成NuGet包。


上面的文章介绍了搭建Web版本的NuGet服务器,以及自动化生成NuGet包的方法


本文介绍简单的NuGet服务器,以及 VS2013自动化生成NuGet包的内容。

一、VS自动生成NuGet包
1、在VS中创建类库项目

技术分享


2、启用NuGet程序包还原(Enable NuGet Package Restore


         在解决方案上右击,选择“ 启用NuGet程序包还原”
技术分享

       确定后会在解决方案中增加一个“.nuget"文件夹,该文件夹有三个文件。

技术分享

     此时,打开项目文件ClassLibrary1.csproj,可以看到类似下面的内容, 注意:下面绿色背景行的内容是否出现在ClassLibrary1.csproj中
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists(‘$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props‘)" />
  <PropertyGroup>
    <Configuration Condition=" ‘$(Configuration)‘ == ‘‘ ">Debug</Configuration>
    <Platform Condition=" ‘$(Platform)‘ == ‘‘ ">AnyCPU</Platform>
    <ProjectGuid>{92A6F604-9829-49FB-8B06-FF2E4C757EC4}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>ClassLibrary1</RootNamespace>
    <AssemblyName>ClassLibrary1</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <SolutionDir Condition="$(SolutionDir) == ‘‘ Or $(SolutionDir) == ‘*Undefined*‘">..\</SolutionDir>
    <RestorePackages>true</RestorePackages>
  </PropertyGroup>
  <PropertyGroup Condition=" ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘ ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" ‘$(Configuration)|$(Platform)‘ == ‘Release|AnyCPU‘ ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists(‘$(SolutionDir)\.nuget\NuGet.targets‘)" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
  <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists(‘$(SolutionDir)\.nuget\NuGet.targets‘)" Text="$([System.String]::Format(‘$(ErrorText)‘, ‘$(SolutionDir)\.nuget\NuGet.targets‘))" />
  </Target>
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</ Project >  
如果没有出现带加号行的内容,需要手动添加上。
第2块绿背景内的代码创建了对.nuget文件夹下的NuGet.targets文件的引用,并添加了缺少NuGet .targets文件的错误信息。
第1块绿背景内的第1行代码创建了 SolutionDir   并设置默认值为项目的父目录, NuGet.targets利用这个配置值来找到他需要的NuGet.exe等资源。
第二行代码, RestorePackages 被设置为True。

3、设置BuildPackages


2中启用了NuGet还原,但是还需要设置让NuGet自动生成nupkg包文件,用记事本打开.csproj文件添加下面1行语句
<BuildPackage>true</BuildPackage>
技术分享
到1下一行的话,Debug和Release编译均生成包
到2 下一行 的话,只用Debug编译才生成包
到3 下一行 的话,只用 Release编译才生成包

4、编译

编译后就可以再bin文件夹下看到 .nupkg文件了




在使用VS自带的版本生成系统时,如果让它自动生成版本的build number和revision number的话,默认情况下生成的build号是从2000年1月1日0点0分以来(到生成这个版本时)所经历的整天数,revision号是所经历的时间减去整天数之后,剩下的秒数 除以2 (不除以2的话,一天有8万多秒,超过了Int16的最大值).


http://www.tuicool.com/articles/N7raEr




搭建自己的NuGet服务器以及在VS中自动生成NuGet包

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值