Ada*_*ler 8 .net versioning msbuild clickonce
我们有一个NAnt脚本,可以从CVS中检出,然后运行MSBuild来发布应用程序.问题是我们必须记住在Visual Studio中总是增加版本.
我们可以选择在发布时自动增加它,但是这会在下次检出时被删除,我宁愿不必让构建脚本检查项目文件.
有一个简单的方法吗?
Kyl*_*Mit 10
MinimumRequiredVersion
自动更新在解决方案资源管理器中,右键单击您的项目并选择卸载项目.
项目不可用后,再次右键单击并选择编辑项目<project_name>.<lang>
.
属性使用键/值对来提取信息
$(OutputPath)
获取元素的值<OutputPath>.\bin</OutputPath>
我们将使用为ClickOnce部署生成的以下属性
<MinimumRequiredVersion>1.0.0.6</MinimumRequiredVersion>
<ApplicationRevision>7</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
Run Code Online (Sandbox Code Playgroud)MSBuild Tasks
可以在项目(*.proj)文件中指定,并在构建事件期间调用.
FormatVersion
是.NET 4.0及更高版本的内置任务,它将ApplicationVersion和ApplicationRevision格式化为单个版本号.将以下代码复制并粘贴到打开的项目文件中,作为根<Project>
元素的子元素.
<Target Name="AutoSetMinimumRequiredVersion" BeforeTargets="GenerateDeploymentManifest">
<FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
<Output PropertyName="MinimumRequiredVersion" TaskParameter="OutputVersion" />
</FormatVersion>
<FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
<Output PropertyName="_DeploymentBuiltMinimumRequiredVersion" TaskParameter="OutputVersion" />
</FormatVersion>
</Target>
Run Code Online (Sandbox Code Playgroud)
此代码将ApplicationVersion和ApplicationRevision作为Format Version任务中的参数,并通过使用完整发布版本覆盖MinimumRequiredVersion来保存输出.
保存并重新加载项目.现在,每个ClickOnce部署都将自动更新到最近发布的版本.
非常感谢Kev 的回答,我已经基本上对此进行了重点介绍,并为所有初学者提供了一些补充说明.这是我发表的关于这个问题的博客文章,在这里我的答案更加广泛.
最后,我使用 NAnt xmlpoke 完成了此操作,因此对于我们最终得到的版本 20.0.dayofyear.hourmonth - 它在各个版本中大多是唯一的。
不需要自定义任务 - 并且较新版本的 MSBuild 也有 pokexml,因此它可能可以使用。
<target name="pokerevision" depends="init">
<property name="projectname" value="MyProject.GUI" />
<!-- This is a bit flawed because 231 could mean 02:31 or 23:01, but we never build before 3 am. -->
<property
name="app.revision"
value="${datetime::get-hour(datetime::now())}${datetime::get-minute(datetime::now())}" />
<echo message="revision: ${app.revision}" />
<xmlpoke
file="${Solution.Path}\${projectname}\${projectname}.csproj"
xpath="//x:Project/x:PropertyGroup[1]/x:ApplicationRevision"
value="${app.revision}"
>
<namespaces>
<namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
</namespaces>
</xmlpoke>
<property
name="app.version"
value="20.0.${datetime::get-day-of-year(datetime::now())}.${app.revision}" />
<echo message="version: ${app.version}" />
<xmlpoke
file="${Solution.Path}\${projectname}\${projectname}.csproj"
xpath="//x:Project/x:PropertyGroup[1]/x:ApplicationVersion"
value="${app.version}"
>
<namespaces>
<namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
</namespaces>
</xmlpoke>
</target>
Run Code Online (Sandbox Code Playgroud)