Is there any MSBuild property that shows what we publish?

I want conditionally undefine DEBUGif it publishes an assembly.

Is there a property that I can check to see if we are publishing now?

+3
source share
3 answers

You can connect to your own goal to set a property from which you can drop behavior, or do whatever you want. The project modification below shows how to connect to existing publication target dependencies with your own before and after the goal. A property is set in front of the object. Then, in the existing part of your project, where DEBUG is defined in the $ (DefineConstants) property, you conditionally decide whether to add DEBUG to the list of constants based on the property that you set when the build is executed due to Publish.

<PropertyGroup>
   <PublishDependsOn>MyBeforePublish;$(PublishDependsOn);MyAfterPublish</PublishDependsOn>
</PropertyGroup>

<Target Name="MyBeforePublish">
   <PropertyGroup>
      <DetectPublishBuild>true</DetectPublishBuild>
   </PropertyGroup>
</Target>
<Target Name="MyAfterPublish">
   <PropertyGroup>
      <DetectPublishBuild>false</DetectPublishBuild>
   </PropertyGroup>
</Target>

...

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
   <PlatformTarget>x86</PlatformTarget>
   <DebugSymbols>true</DebugSymbols>
   <DebugType>full</DebugType>
   <Optimize>false</Optimize>
   <OutputPath>bin\Debug\</OutputPath>
   <DefineConstants>TRACE</DefineConstants>
   <DefineConstants
      Condition="'$(DetectPublishBuild)' != 'true'"
      >DEBUG;$(DefineConstants)</DefineConstants>
   <ErrorReport>prompt</ErrorReport>
   <WarningLevel>4</WarningLevel>
</PropertyGroup>
+3
source
<Choose>
      <When Condition="'$(BuildType)' == 'publish'">
         <PropertyGroup>
           <DefineConstants>Release</DefineConstants>
         </PropertyGroup>
      </When>      
</Choose>

You may need values ​​other than release. But that should work.

, , . , , .

+1
<Copy SourceFiles="Web.Base.config" DestinationFiles="Web.config" OverwriteReadOnlyFiles="True" Condition="!('$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == '')" />

"" , PublishProfile.

http://sedodream.com/2013/01/06/commandlinewebprojectpublishing.aspx

+1
source

All Articles