Using $(OutDir) in a property group of a property sheet

Using Visual Studio 2022 with a C++ solution.

The below property sheet is working fine:

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <ItemGroup>
    <CopyFileToFolders Include="$(MSBuildThisFileDirectory)somefile.bin">
      <DeploymentContent>true</DeploymentContent>
      <FileType>Document</FileType>
      <DestinationFolders>$(OutDir)</DestinationFolders>
    </CopyFileToFolders>
  </ItemGroup>

</Project>

But the below one is not working (when output directory is changed in project properties):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <CustomDestination>$(OutDir)</CustomDestination>
  </PropertyGroup>

  <ItemGroup>
    <CopyFileToFolders Include="$(MSBuildThisFileDirectory)somefile.bin">
      <DeploymentContent>true</DeploymentContent>
      <FileType>Document</FileType>
      <DestinationFolders>$(CustomDestination)</DestinationFolders>
    </CopyFileToFolders>
  </ItemGroup>

</Project>

This makes sense as “CustomDestination” property is evaluated before “OutDir” is well-defined from VS IDE, on the contrary to the “CopyFileToFolder”->”DestinationFolders” item metadata which is evaluated after all properties.

Is there an elegant way to predefine “CustomDestination” with any value including some $(X) before the “CopyFileToFolders” item, so I can move both on separate property sheets ?

_

Additional note:

  1. I came out with the below workaround consisting in managing $(OutDir) separately like this:
<PropertyGroup>
  <CustomDestination>$(ProjectDir);$(SolutionDir)SomeDirectory</CustomDestination>
  <UseOutDir>Yes</UseOutDir>
</PropertyGroup>

<ItemGroup>
  <CopyFileToFolders Include="$(MSBuildThisFileDirectory)somefile.bin">
    <DeploymentContent>true</DeploymentContent>
    <FileType>Document</FileType>
    <DestinationFolders Condition="'$(UseOutDir)' == ''">$(CustomDestination) </DestinationFolders>
    <DestinationFolders Condition="'$(UseOutDir)' != ''">$(OutDir);$(CustomDestination) </DestinationFolders>
  </CopyFileToFolders>
</ItemGroup>

But I was wondering if someone would come out with a more generic solution.

  1. I also tried something like this:
  <PropertyGroup>
    <CustomDestination>%24(OutDir);%24(ProjectDir)</CustomDestination>
  </PropertyGroup>

  <ItemGroup>
    <CopyFileToFolders Include="$(MSBuildThisFileDirectory)somefile.bin">
      <DeploymentContent>true</DeploymentContent>
      <FileType>Document</FileType>
      <DestinationFolders>$(CustomDestination)</DestinationFolders>
    </CopyFileToFolders>
  </ItemGroup>

But I don’t know how to make VS/MSBuild to replace $(X) contents into $(CustomDestination) property value.

6

I found a solution !

Defining “CustomDestination” as a custom item value instead of a property makes it evaluated after properties, then with the latest $(OutDir) value.

  <!--Define CustomDestination-->
  <ItemGroup>
    <CustomDestination Include="$(OutDir)" />
  </ItemGroup>

  <!--Print CustomDestination value in build output-->
  <Target Name="PrintDestTarget" BeforeTargets="Build">
    <Message Importance="high" Text="PrintDestTarget: CustomDestination = '@(CustomDestination)'" />
  </Target>

  <!--Use CustomDestination value to copy file-->
  <ItemGroup>
    <CopyFileToFolders Include="$(MSBuildThisFileDirectory)somefile.bin">
      <DeploymentContent>true</DeploymentContent>
      <FileType>Document</FileType>
      <DestinationFolders>@(CustomDestination)</DestinationFolders>
    </CopyFileToFolders>
  </ItemGroup>

Note that the setup logic of items is different than properties:

<ItemGroup>
  <CustomDestination Include="Smith" />
</ItemGroup>
<ItemGroup>
  <CustomDestination Include="Adams" />
</ItemGroup>
<Target Name="PrintDestTarget" BeforeTargets="Build">
  <Message Importance="high" Text="PrintDestTarget: CustomDestination = '@(CustomDestination)'" />
</Target>

Will output “Smith;Adams”.

I am not shure if it is possible to modify an item value, but one can still define new ones as needed.

From looking at your property sheet, it seems you want to copy somefile.bin to your custom path. I copied your property sheet (You said the one is not working) to my local c++ project for test and it worked fine. It can recognize $(CustomDestination) defined in PropertyGroup.

Here is my test result:

ENV: Visual Studio 2022(17.10.4)

But the below one is not working

Do you mean the task CopyFileToFolders is unable to copy somefile.bin file to your custom destination or it can not evaluate $(CustomDestination)? And could you see warning/error messages during the build process?

If you want to make sure whether “CustomDestination” property is evaluated before “CopyFileToFolders” item, you can directly print their values.

<Target Name="test">
  <Message Text="'%(CopyFileToFolders.FileType)'" />
  <Message Text="'%(CopyFileToFolders.DestinationFolders)'" />
</Target>

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật