Voo*_*Voo 18 c# nuget nuget-package visual-studio-2013 nuget-spec
我们有一个框架,在一个解决方案中分成许多单独的项目.我现在想为每个单独的项目创建NuGet包,但保证只能在一个解决方案中使用一个版本的框架(可能跨多个项目).
例如,假设框架由两个项目组成:
Framework
Framework_1
Framework_2
Run Code Online (Sandbox Code Playgroud)
现在,当使用此框架时,一个项目可能会引用Framework_1,而另一个项目引用Framework_2.我想确保两个软件包具有相同的版本(如果有一个简单的单步过程升级到新版本,则可获得奖励积分)
我想我会定义一个解决方案级别的Framework包,所有其他包都严格依赖它.问题是NuGet只需安装多个版本的解决方案级别包就没有问题.
基本上我尝试了以下内容:
解决方案级别的nuspec文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>My.Framework</id>
<version>1.0.0</version>
<title>My.Framework</title>
<authors>voo</authors>
<owners>voo</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Some Framework Solution Package</description>
<copyright>Copyright © 2015</copyright>
</metadata>
</package>
Run Code Online (Sandbox Code Playgroud)
和一个nuspec包的一部分:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>My.Framework.BL</id>
<version>1.0.0</version>
<title>My.Framework.BL</title>
<authors>voo</authors>
<owners>voo</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Business Layer</description>
<copyright>Copyright © 2015</copyright>
<dependencies>
<dependency id="My.Framework" version="[1.0.0]"/>
</dependencies>
</metadata>
</package>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,如果我尝试安装,说另一个My.Framework.EF带有版本的软件包,1.0.1并且对My.Framework1.0.1 的显式依赖Visual Studio只会安装My.Framework两次 - 一次使用版本1.0.0,一次使用1.0.1.
您可以通过在packages.config中使用以下语法来约束包的版本,如:
<package id="jQuery" version="1.9.1" allowedVersions="[1.9.1]" />
Run Code Online (Sandbox Code Playgroud)
同样来自原始nuget文档:创建NuGet包时,可以在.nuspec文件中指定包的依赖关系.
<dependency id="ExamplePackage" version="[1,3)" />
Run Code Online (Sandbox Code Playgroud)
在示例中,版本1和版本2.9是可接受的,但不是0.9或3.0.
我认为您可以通过这种方式将其限制为单个或特定范围的版本. 在这里,您可以阅读更多相关信息.
事实证明,您可以在Install.ps1Install-Package $package.Id -version <someVersion> 内部调用,这将导致原来安装的版本被卸载并安装指定的版本。
稍微简化的版本如下:
param($installPath, $toolsPath, $package, $project)
function GetInstallingVersion() {
$package.Version
}
# Gets the current version of the used framework.
# If no framework is yet installed, we set the framework version
# to the one that's being installed right now.
function GetCurrentFrameworkVersion() {
$solutionPath = Split-Path $dte.Solution.FileName
$fwkVersionFile = "${solutionPath}\framework_version.txt"
if (Test-Path $fwkVersionFile) {
return Get-Content $fwkVersionFile
}
else {
$installingVersion = GetInstallingVersion
$installingVersion > $fwkVersionFile
return $installingVersion
}
}
$currentFwkVersion = GetCurrentFrameworkVersion
$installingVersion = GetInstallingVersion
if ($currentFwkVersion -ne $installingVersion) {
Install-Package $package.Id -version $currentFwkVersion
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1281 次 |
| 最近记录: |