<p>Is there a way to disallow publishing of debug builds with ClickOnce?</p>

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

<p>We're publishing the build from within Visual Studio.</p>

[{'answer_id': 865822, 'author': 'Judah Gabriel Himango', 'author_id': 536, 'author_profile': 'https://Stackoverflow.com/users/536', 'pm_score': 3, 'selected': False, 'text': '<p>One thing you can do is add a condition to the .csproj or .vbproj file that MSBuild will check when doing a build. </p>\n\n<p>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.</p>\n\n<p>An example might be something like this:</p>\n\n<pre><code>&lt;Choose&gt;\n    &lt;When Condition=" \'$(Configuration)\'==\'Debug\' "&gt;\n        &lt;Exec Command="C:\\foo.bat" ContinueOnError="false" /&gt;\n    &lt;/When&gt;\n &lt;/Choose&gt;\n</code></pre>\n\n<p>Where foo.bat is a batch file that return non-zero, thus stopping the publish from occurring.</p>\n'}, {'answer_id': 6738914, 'author': 'Rodrigo Britto', 'author_id': 850784, 'author_profile': 'https://Stackoverflow.com/users/850784', 'pm_score': 2, 'selected': False, 'text': '<p>I have chosen another solution that worked for me:</p>\n\n<p>I couldn\'t change my build process. So I did <em>Tools</em> → <em>Customize...</em> 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!</p>\n\n<p>With this I considerably reduced the risk of human error. Those buttons should always be together.</p>\n'}, {'answer_id': 15080048, 'author': 'Sam Storie', 'author_id': 571237, 'author_profile': 'https://Stackoverflow.com/users/571237', 'pm_score': 7, 'selected': True, 'text': '<p>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:</p>\n\n<pre><code>&lt;!-- The following makes sure we don’t try to publish a configuration that defines the DEBUG constant --&gt;\n&lt;Target Name="BeforePublish"&gt;\n    &lt;Error Condition="\'$(DebugSymbols)\' == \'true\'" Text="You attempted to publish a configuration that defines the DEBUG constant!" /&gt;\n&lt;/Target&gt;\n</code></pre>\n\n<p>Just place it at the end of the file, right before the <code>&lt;/Project&gt;</code> tag.</p>\n\n<p>(original source: <a href="http://www.nathanpjones.com/wp/2010/05/preventing-clickonce-publishing-a-debug-configuration/comment-page-1/#comment-625">http://www.nathanpjones.com/wp/2010/05/preventing-clickonce-publishing-a-debug-configuration/comment-page-1/#comment-625</a>)</p>\n'}]
['https://Stackoverflow.com/questions/47107', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3641/']