The old .NET Framework project system ignores conditions on Items/ItemGroups 
(Choose is a workaround).

The new SDK-based project system doesn't suffer from this problem, and honors 
conditions on everything.

From: ozdotnet-boun...@ozdotnet.com <ozdotnet-boun...@ozdotnet.com> On Behalf 
Of Preet Sangha
Sent: Wednesday, August 11, 2021 5:40 PM
To: ozDotNet <ozdotnet@ozdotnet.com>
Subject: Re: Publish conditional

And perhaps use the Choose statement? 
https://docs.microsoft.com/en-us/visualstudio/msbuild/choose-element-msbuild?view=vs-2019<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fvisualstudio%2Fmsbuild%2Fchoose-element-msbuild%3Fview%3Dvs-2019&data=04%7C01%7Cdavid.kean%40microsoft.com%7C6bd0f5caefe4455d81e508d95c9b47d3%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637642644292802101%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=S0ZXrP6Lkt017KrnyCqtbLd9i82CAYaVB3%2FYudRRxlw%3D&reserved=0>

regards,
Preet, in Auckland NZ



On Wed, 11 Aug 2021 at 19:37, Preet Sangha 
<preetsan...@gmail.com<mailto:preetsan...@gmail.com>> wrote:
This might be relevant: 
https://stackoverflow.com/a/28874918/30225<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fa%2F28874918%2F30225&data=04%7C01%7Cdavid.kean%40microsoft.com%7C6bd0f5caefe4455d81e508d95c9b47d3%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637642644292802101%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=VDpY92qblxPMLg8ctC%2B8qmE3qrghx6u8kSLzgM%2F07X4%3D&reserved=0>

> While conditional import statements work in command-line MSBuilds,
> they do not work with MSBuild in the Visual Studio integrated
> development environment (IDE). Conditional imports are evaluated by
> using the configuration and platform values that are set when the
> project is loaded. If changes are subsequently made that require a
> reevaluation of the conditionals in the project file, for example,
> changing the platform, Visual Studio reevaluates the conditions on
> properties and items, but not on imports. Because the import
> conditional is not reevaluated, the import is skipped. To work around
> this, put conditional imports in the .targets files or put code in a
> conditional block such as a Choose Element (MSBuild) block.

I think this is true for `ItemGroup` element also...

regards,
Preet, in Auckland NZ



On Wed, 11 Aug 2021 at 18:52, Greg Keogh 
<gfke...@gmail.com<mailto:gfke...@gmail.com>> wrote:
Folks, I need to publish different *.js files depending upon the selected 
$(Configuration). I have VS2019 configs for Debug, AU region and US region. I 
tried editing the csproj file to have conditions around the files, like this 
fragment for the US.

  <ItemGroup Condition="'$(Configuration)'=='Release US'">
    <Content Include="wwwroot\script\app-us.js"/>
  </ItemGroup>

It does nothing, so I tried <None Remove> and <Content Remove> and 
CopyToPublishDirectory in a dozen combinations, but I either get no files or 
all files. I'm clearly bumbling around uselessly, so maybe someone has done 
this before and can reveal what tricks are required.

I'm just using VS2019 publish project command, so that's when I want the 
conditions to run. Maybe ItemGroup conditions are meaningless for publish? I 
dunno because web searches produce confusing and contradictory samples and the 
MSDN documentation doesn't seem to cover what I'm doing.

Thanks,
Greg

Reply via email to