How can I include different files when publishing to Mac and PC?

GuruGurra 21 Reputation points

I have a .Net Core (3.1) project that can be run on both PC and Mac. One source file (a json file) needs to have different content depending on the platform I'm publishing to.

Is it possible to have two different versions of the file in my project somehow have the correct version copied/renamed depending on publish target? If so - how? If not - is there some other way I can do this without having to rename the file myself after publishing it?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,599 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,946 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 27,181 Reputation points Microsoft Vendor

    Hello @GuruGurra ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    You can try to add following codes to your .XXproj file.(right-click your project > select Unload Project > click your project and select Edit Project File)

        <Content Update="XXXX\XXXX\XXXXX" Condition="'$(RuntimeIdentifier)'=='win-x64'">     

    Replace XXXX\XXXX\XXXXX and add the file path that you'd like(or not) to use(the json file).

    The <Content> tag represents files that are not compiled into the project, but may be embedded or published together with it.

    You can select the RID that you want(or not) for publishing to PC or MAC, for example win-x64 for "Portable(.NET Core 2.0 or later versions)".

    The <CopyToPublishDirectory> tag helps to exclude the specified file when you publish your project.(It includes these values: Never, Always, PreserveNewest)

    Hope this helps.


    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    1 person found this answer helpful.
    0 comments No comments

  2. GuruGurra 21 Reputation points

    I added the following section to my project file:

        <Content Update="Manifest\PC\manifest.json" Condition="'$(RuntimeIdentifier)'=='win-x64'">
        <Content Update="Manifest\Mac\manifest.json" Condition="'$(RuntimeIdentifier)'=='osx.10.12-x64'">

    and added the different manifest.json files in in the "Manifest\PC" and "Manifest\Mac" folders in my project folder.

    Nothing happens when I publish the project - no manifest files are present in the published folder.

  3. GuruGurra 21 Reputation points

    Hi @Tianyu Sun-MSFT

    First - thanks for the very extensive answer.

    I have a console application and publish to a local folder.

    At least it were a console application prior to the update to version 16.8.1 of Visual Studio. That update broke my project by injecting things in the project file that forced it to be a Windows application (and impossible to build). (We have discussed that in another thread). I found the following entry in the project file, and when I removed it my project went back to being a console application.


    I don't know why it was injected and I don't know if the VS update also made other changes to my project file.

    I would say that my configuration on the most parts is identical to yours. The only very obvious (and probably important) difference is that I don't have any FolderProfile.pubxml file. How is that file created? I have two defined folder profiles - one for PC and one for Mac but I don't have any *.pubxml files anywhere in my project file structure.