none
String substitution in the expanded value of %(RecursiveDir) metadata. RRS feed

  • Question

  • Let me preface this by saying that I have almost no experience in hacking on MsBuild. Usually Visual Studio just does what I need. So, it is entirely possible that I am barking up the wrong tree and there is a much simpler way to get to where I want to go.

    I am working on getting a Linux with VC++ project up and running. It uses some third party libraries, which we have under source control. These libraries are pre-built and are not part of the VS solution/project files, but are staged via our SCM tool and referenced using "additional include directories" and "additional library directories" settings.

    Rather than install the SCM client on the Linux build machine and invoke a sync command as part of the build using the "Remote Pre-Build Event", I was hoping to simply copy the required headers and libraries from the Windows machine to the Linux build target using the "Additional Sources To Copy" setting.

    Towards this end, I added an ItemGroup to my vcxproj file and set the "Additional Sources To Copy" setting as follows:

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">  
      <AdditionalSourcesToCopyMapping>
        @(ExtraIncludes -> '%(FullPath) := $(RemoteProjectDir)/%(RecursiveDir)/%(Filename)%(Extension)')
      </AdditionalSourcesToCopyMapping>
    </PropertyGroup>
    <ItemGroup>
      <ExtraIncludes Include="$(SolutionDir)..\..\deps\libraryXYZ\include\**" />
    </ItemGroup>

    This works fine as long as %(RecursiveDir) is only a single directory level deep. But when there is more than one level, %(RecursiveDir) contains an embedded '\' that needs to change to '/' to work as desired on the Linux machine.

    I am aware that I can invoke a function on an item list like @(ExtraIncludes -> Replace('\','/')). This is sort of what I want to do, but I need to perform this on metadata rather than an item list.

    So, is there a good way to achieve what I want here, or do I need to stop digging this hole and pursue a different path?

    Many Thanks,

    Derek Shinaberry

    Tuesday, August 20, 2019 2:17 PM

Answers

  • Hi Perry,

    No, it didn't work.The ** was just passed through and became a literal on the subsequent copy command.

    I wound up using the following which chained a replace after the transform. The Windows side apparently handles the Unix path separators without a problem. Go figure.

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">  
      <AdditionalSourcesToCopyMapping>
        @(ExtraIncludes -> '%(FullPath) := $(RemoteProjectDir)/%(RecursiveDir)/%(Filename)%(Extension)'->Replace('\','/'))
      </AdditionalSourcesToCopyMapping>
    </PropertyGroup>

    Thanks,

    Derek

    Thursday, August 22, 2019 8:24 PM

All replies

  • Hi Derek,

    Welcome to the MSDN forum.

    According to your description ,we suggest you can use the wildcard character.

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">  
      <AdditionalSourcesToCopyMapping>
        @(ExtraIncludes -> '%(FullPath) := $(RemoteProjectDir)/%(RecursiveDir)/**/%(Filename)%(Extension)')
      </AdditionalSourcesToCopyMapping>
    </PropertyGroup>

    You can try these steps to check whether it works.

    More information you can refer to this:

    https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-items?view=vs-2019

    If it does not work, you can import them by adding reference in itemgroup and copy these files to the current project. 

    Hope it could help you.

    Best Regards,

    Perry




    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Wednesday, August 21, 2019 9:27 AM
  • Hi Derek,

    Did your issue solved?  Do you have any update? If your issue still persists, please feel free to let us know.

    Thanks for your understanding.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Thursday, August 22, 2019 9:57 AM
  • Hi Perry,

    No, it didn't work.The ** was just passed through and became a literal on the subsequent copy command.

    I wound up using the following which chained a replace after the transform. The Windows side apparently handles the Unix path separators without a problem. Go figure.

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">  
      <AdditionalSourcesToCopyMapping>
        @(ExtraIncludes -> '%(FullPath) := $(RemoteProjectDir)/%(RecursiveDir)/%(Filename)%(Extension)'->Replace('\','/'))
      </AdditionalSourcesToCopyMapping>
    </PropertyGroup>

    Thanks,

    Derek

    Thursday, August 22, 2019 8:24 PM
  • Hi Derek,

    We are glad to hear that your issue is solved.

    We suggest you can mark your reply as answer to help other community members search similar issues.

    Thanks for your understanding.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, August 23, 2019 9:10 AM