Question

Is there a way to disallow publishing of debug builds with ClickOnce?

I only want to allow release builds through, but right now human error causes a debug build to slip through once in a while.

We're publishing the build from within Visual Studio.

Was it helpful?

Solution

One thing you can do is add a condition to the .csproj or .vbproj file that MSBuild will check when doing a build.

The condition would check if a publish is occurring and check if the build is a debug build, then do something like run an external tool or otherwise interrupt the build process or cause it to fail.

An example might be something like this:

<Choose>
    <When Condition=" '$(Configuration)'=='Debug' ">
        <Exec Command="C:\foo.bat" ContinueOnError="false" />
    </When>
 </Choose>

Where foo.bat is a batch file that return non-zero, thus stopping the publish from occurring.

OTHER TIPS

I have started to modify the .csproj files to include the following code to throw an error for debug deploys, effectively preventing the deploy from happening:

<!-- The following makes sure we don’t try to publish a configuration that defines the DEBUG constant -->
<Target Name="BeforePublish">
    <Error Condition="'$(DebugSymbols)' == 'true'" Text="You attempted to publish a configuration that defines the DEBUG constant!" />
</Target>

Just place it at the end of the file, right before the </Project> tag.

(original source: http://www.nathanpjones.com/wp/2010/05/preventing-clickonce-publishing-a-debug-configuration/comment-page-1/#comment-625)

I have chosen another solution that worked for me:

I couldn't change my build process. So I did ToolsCustomize... and change the text of the action, adding an alert like "Publish [CONFIGURE TO RELEASE!]", and placing the Publish button next to the Debug/Release configuration option. It's easy!

With this I considerably reduced the risk of human error. Those buttons should always be together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top