如果是发布版本,我希望你能有条件地取消定义DEBUG
。
是否有一个属性可以检查当前是否正在发布?
在VS2019 16.10.1中进行测试。
<Target Name="XXX" Condition="'$(PublishProtocol)'!=''">
<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>
<Copy SourceFiles="Web.Base.config" DestinationFiles="Web.config" OverwriteReadOnlyFiles="True" Condition="!('$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == '')" />
http://sedodream.com/2013/01/06/commandlinewebprojectpublishing.aspx
_IsPublishing
,可以用来检查是否处于发布构建状态。
如果我们确实执行了 dotnet publish
,此变量将包含 yes
;如果未执行,则为空。dotnet build /t:Publish
或 msbuild /t:Publish
时,该变量不会被设置。<Choose>
<When Condition="'$(BuildType)' == 'publish'">
<PropertyGroup>
<DefineConstants>Release</DefineConstants>
</PropertyGroup>
</When>
</Choose>
除了发布之外,您可能还需要其他值。但是,这应该可以工作。
我们在我们的地方所做的是实际上有一个发布、调试和发布。我们通过将其从发布中复制来创建发布,因此它具有所有设置。
$(BuildType)
似乎是用户定义的,因此不能直接使用。 - Jack Miller