禁止发布ClickOnce部署的调试版本

时间:2023-01-20 20:39:37

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

有没有办法禁止使用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.

我们从Visual Studio中发布构建。

3 个解决方案

#1


7  

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

您可以做的一件事是向.csproj或.vbproj文件添加一个条件,MSBuild在进行构建时会检查该文件。

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.

其中foo.bat是一个返回非零的批处理文件,因此停止发布。

#2


48  

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:

我已经开始修改.csproj文件以包含以下代码,以便为调试部署引发错误,从而有效地防止部署发生:

<!-- 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)

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

#3


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.

有了这个,我大大降低了人为错误的风险。那些按钮应该总是在一起。

#1


7  

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

您可以做的一件事是向.csproj或.vbproj文件添加一个条件,MSBuild在进行构建时会检查该文件。

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.

其中foo.bat是一个返回非零的批处理文件,因此停止发布。

#2


48  

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:

我已经开始修改.csproj文件以包含以下代码,以便为调试部署引发错误,从而有效地防止部署发生:

<!-- 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)

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

#3


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.

有了这个,我大大降低了人为错误的风险。那些按钮应该总是在一起。