22

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.

4

3 回答 3

58

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)

于 2013-02-26T01:56:50.843 回答
8

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.

于 2009-05-14T21:17:30.437 回答
3

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.

于 2011-07-18T20:21:00.163 回答