Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Last active September 22, 2020 15:25
Show Gist options
  • Save smailliwcs/69f8e6f4100653058e3f77b9bcd43271 to your computer and use it in GitHub Desktop.
Save smailliwcs/69f8e6f4100653058e3f77b9bcd43271 to your computer and use it in GitHub Desktop.
Taming ClickOnce deployments
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDir>$(SolutionDir)Build\</BuildDir>
<Rebuilding>false</Rebuilding>
</PropertyGroup>
<PropertyGroup Condition="'$(OutputType)' == 'Exe' Or '$(OutputType)' == 'WinExe'">
<StartAction>Program</StartAction>
<StartWorkingDirectory>$(BuildDir)</StartWorkingDirectory>
<StartProgram>$(BuildDir)$(TargetFileName)</StartProgram>
</PropertyGroup>
<Target Name="FlagRebuild" BeforeTargets="BeforeRebuild">
<PropertyGroup>
<Rebuilding>true</Rebuilding>
</PropertyGroup>
</Target>
<Target Name="CopyBuildFiles" AfterTargets="Build">
<ItemGroup>
<BuildFile Include="$(TargetDir)**\*" />
</ItemGroup>
<Copy SourceFiles="@(BuildFile)" DestinationFolder="$(BuildDir)%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="CleanBuildDir" AfterTargets="Clean" Condition="'$(Rebuilding)' == 'false'">
<RemoveDir Directories="$(BuildDir)" />
</Target>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDir>$(SolutionDir)Build\</BuildDir>
</PropertyGroup>
<ItemGroup>
<Content Include="$(BuildDir)**" Exclude="$(BuildDir)**\*.pdb">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="CleanPublishDir" AfterTargets="Clean">
<RemoveDir Directories="publish" />
</Target>
</Project>
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
public class Program
{
[STAThread]
internal static void Main(string[] args)
{
try
{
DirectoryInfo directory = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
string executable = Path.Combine(directory.FullName, "Program.exe");
Process.Start(new ProcessStartInfo
{
UseShellExecute = false,
WorkingDirectory = directory.FullName,
FileName = executable
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment