MinimumRequiredVersion
在解决方案资源管理器中,右键单击项目并选择卸载项目。
一旦项目变为不可用状态,再次右键单击并选择编辑<project_name>.<lang>
proj。
Properties use key/value pairs to extract information
$(OutputPath)
to obtain the value for the element <OutputPath>.\bin</OutputPath>
We’ll use the following properties generated for a ClickOnce deployment
<MinimumRequiredVersion>1.0.0.6</MinimumRequiredVersion>
<ApplicationRevision>7</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
MSBuild Tasks
can be specified in the project (*.proj) file and invoked during a build event.
FormatVersion
is a built-in task for .NET 4.0 and later that formats the ApplicationVersion and ApplicationRevision into a single version number.Copy and Paste the following code into the opened project file as a child element to the root <Project>
element.
<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>
This code will take ApplicationVersion and ApplicationRevision as parameters in the Format Version task and will save the output by overwriting the MinimumRequiredVersion with the full publish version.
Save and reload your project. Every ClickOnce deployment will now automatically update to the most recently published version.
<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>
你有几个选项,以下是两个示例:
指定星号代替构建版本号以自动增加。
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx
[assembly: AssemblyVersion("1.0.*")]
使用 MSBuild 扩展包中的 AsssemblyInfo msbuild 任务。
http://msbuildextensionpack.codeplex.com
示例:
http://www.msbuildextensionpack.com/help/4.0.4.0/html/d6c3b5e8-00d4-c826-1a73-3cfe637f3827.htm
编辑
抱歉,我误读了你的问题。
在这里可以查看Jason Stangroome所接受的答案:
如何让ClickOnce发布版本匹配AssemblyInfo.cs文件版本?