Publish Multiple version application through ClickOnce and MSBuild


If we want to install multiple version application through ClickOnce on one machine.
We must change the AssemblyName and ProductName when publish the application at least.
For example, we deploy a application like MyProject.WPFApp


If we want to deploy a Alpha version, we must change the AssemblyName like MyProject.WPFAppAlpha
Then you can publish the application and install through ClickOnce.

Modify Project File Directly

For example, Modify MyProject.WPFApp.proj

1.Modify Assembly Name

    <AssemblyName>MyProject.WPFApp</AssemblyName>
To
    <AssemblyName>MyProject.WPFAppAlpha</AssemblyName>

2.Modiy Product Name

    <ProductName>WPFApp</ProductName>
TO
    <ProductName>WPFApp Alpha</ProductName>

3.Modify Publish .exe and .exe.manifest

  <ItemGroup>
    <PublishFile Include="MyProject.WPFApp.exe">
      <Visible>False</Visible>
      <PublishState>Auto</PublishState>
      <IncludeHash>False</IncludeHash>
      <Group>
      </Group>
      <TargetPath>
      </TargetPath>
      <FileType>ManifestEntryPoint</FileType>
    </PublishFile>
    <PublishFile Include="MyProject.WPFApp.exe.manifest">
      <Visible>False</Visible>
      <PublishState>Auto</PublishState>
      <IncludeHash>False</IncludeHash>
      <Group>
      </Group>
      <TargetPath>
      </TargetPath>
      <FileType>ManifestEntryPoint</FileType>
    </PublishFile>
TO
  <ItemGroup>
    <PublishFile Include="MyProject.WPFAppAlpha.exe">
      <Visible>False</Visible>
      <PublishState>Auto</PublishState>
      <IncludeHash>False</IncludeHash>
      <Group>
      </Group>
      <TargetPath>
      </TargetPath>
      <FileType>ManifestEntryPoint</FileType>
    </PublishFile>
    <PublishFile Include="MyProject.WPFAppAlpha.exe.manifest">
      <Visible>False</Visible>
      <PublishState>Auto</PublishState>
      <IncludeHash>False</IncludeHash>
      <Group>
      </Group>
      <TargetPath>
      </TargetPath>
      <FileType>ManifestEntryPoint</FileType>
    </PublishFile>

After publish, you can find a MyProject.WPFAppAlpha in you publish directory.
Then you can install the MyProject.WPFApp and MyProject.WPFAppAlpha on one machine through ClickOnce.

Publish with MSBuild automaticly

But it is not good to modify the projct file every time when you publish different version.
We can use MSBuild to publish the automaticly with different property.

For example, we have a MSBuild Strpt, we can define following property

    <PublishProductName>#PublishProductName#</PublishProductName>
    <PublishAssemblyName>#PublishAssemblyName#</PublishAssemblyName>

When publish different version, we only change the #PublishProductName# and #PublishAssemblyName# values.

<MSBuild Projects="MyProject.WPFApp.csproj" Targets="Publish" Properties="Configuration=Release;PublishProductName=$(PublishProductName);PublishAssemblyName=$(PublishAssemblyName);"/>

We can pass the two property values to the proj file and change the AssemblyName and ProductName dymamicly.

1.Modify Assembly Name

    <!—Visual Studio will use this as default value when you view project properties –>
    <AssemblyName>MyProject.WPFApp</AssemblyName>
    <AssemblyName Condition=" '$(PublishAssemblyName)' != '' ">$(PublishAssemblyName)</AssemblyName>

2.Modiy Product Name

    <ProductName>WPFApp</ProductName>
    <ProductName Condition=" '$(PublishProductName)' != '' ">$(PublishProductName)</ProductName>

3.Publish .exe and .exe.manifest

  <ItemGroup>
    <PublishFile Include=".exe">
      <Visible>False</Visible>
      <PublishState>Auto</PublishState>
      <IncludeHash>False</IncludeHash>
      <Group>
      </Group>
      <TargetPath>
      </TargetPath>
      <FileType>ManifestEntryPoint</FileType>
    </PublishFile>
    <PublishFile Include=".exe.manifest">
      <Visible>False</Visible>
      <PublishState>Auto</PublishState>
      <IncludeHash>False</IncludeHash>
      <Group>
      </Group>
      <TargetPath>
      </TargetPath>
      <FileType>ManifestEntryPoint</FileType>
    </PublishFile>

.exe and .exe.manifest are very strange, but they works with visual studio publih.
You also can change ApplicationVersion in this way.
So the stable version and alpha version can update separately.

posted @ 2010-07-06 21:36  kevinzx  阅读(989)  评论(0编辑  收藏  举报