Answers: <p>Finally, I have received the result as it was intended to be.</p>
  <p>This <a href="https://stackoverflow.com/a/71239913/20737189">answer</a> was the final clue. And I did find the reference in Microsoft <a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/" rel="nofollow noreferrer">documentation</a>.</p>
  <p><a href="https://i.sstatic.net/QrCSH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QrCSH.png" alt="enter image description here" /></a></p>
  <p>These properties are set in the project file:</p>
  <pre class="lang-xml prettyprint-override"><code>    &lt;PublishSingleFile&gt;true&lt;/PublishSingleFile&gt;
      &lt;IncludeAllContentForSelfExtract&gt;true&lt;/IncludeAllContentForSelfExtract&gt;
  </code></pre>
  <p>There was a <a href="https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/runtimespecific-app-default" rel="nofollow noreferrer">change</a> in the publish process by Microsoft. If PublishSingleFile is set to true, Self-Contained is implied automatically.<br />
  When the above properties are set in the project file, they do not need to be listed as arguments in the command line.</p>
  <p>The <em><strong>DotNetCoreCLI@2</strong></em> task looks like this:</p>
  <pre class="lang-yaml prettyprint-override"><code>steps:
  - task: DotNetCoreCLI@2
    displayName: 'Publish *.csproj'
    inputs:
      command: publish
      publishWebProjects: false
      projects: '**/DevOpsWpf.csproj'
      arguments: '-c Release -r win-x64 --output $(build.artifactstagingdirectory)'
      zipAfterPublish: false
  </code></pre>
  <p>The <em><strong>project file</strong></em> looks like this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;OutputType&gt;WinExe&lt;/OutputType&gt;
      &lt;TargetFramework&gt;net8.0-windows10.0.19041.0&lt;/TargetFramework&gt;
      &lt;Nullable&gt;enable&lt;/Nullable&gt;
      &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
      &lt;UseWPF&gt;true&lt;/UseWPF&gt;
      &lt;PublishSingleFile&gt;true&lt;/PublishSingleFile&gt;
      &lt;IncludeAllContentForSelfExtract&gt;true&lt;/IncludeAllContentForSelfExtract&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;CommunityToolkit.Mvvm&quot; Version=&quot;8.2.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Configuration&quot; Version=&quot;8.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.DependencyInjection&quot; Version=&quot;8.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Hosting&quot; Version=&quot;8.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Logging&quot; Version=&quot;8.0.0&quot; /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;ProjectReference Include=&quot;..\DevOpsWpf.Library\DevOpsWpf.Library.csproj&quot; /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;None Update=&quot;appsettings.Development.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;appsettings.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
        &lt;ExcludeFromSingleFile&gt;True&lt;/ExcludeFromSingleFile&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;appsettings.Production.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;Documentations\ReadMe.txt&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;Properties\launchSettings.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
    &lt;/ItemGroup&gt;
    
  &lt;/Project&gt;
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-02-14T15:11:20.087Z
Answers: 2024-02-14T15:11:20.087Z
Answers: karwenzman
Body: <h3>The settings</h3>
  <p>My goal is to understand the CI/CD process on Azure (and in general). For that, I have build a little Wpf-App. It is not doing much. Just displaying a simple ReadMe.txt file.<br />
  A test project is included and the tests are running fine.<br />
  Also, I am practicing app-configuration by replacing placeholders in appsettings.json by varibles in azure-pipelines.yml. This is running as supposed.</p>
  <h3>The goal to accomplish</h3>
  <p>Now I am working on publishing a self-contained exe-file that is excluding appsettings.json. That is where I do need some help. <strong>Is this task configured, properly?</strong></p>
  <pre class="lang-yml prettyprint-override"><code>- task: DotNetCoreCLI@2
    displayName: 'Publish'
    inputs:
      command: publish
      publishWebProjects: false
      arguments: '-c $(buildConfiguration) -r $(runtimeId) --self-contained true --output $(build.artifactstagingdirectory)'
      zipAfterPublish: false
    enabled: true
  </code></pre>
  <h3>References</h3>
  <ul>
  <li><a href="https://learn.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli" rel="nofollow noreferrer">PublishAppsWithCli</a></li>
  <li><a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops" rel="nofollow noreferrer">AzurePipelines</a></li>
  <li><a href="https://www.youtube.com/playlist?list=PLLWMQd6PeGY0bEMxObA6dtYXuJOGfxSPx" rel="nofollow noreferrer">TrainingCourse</a> (Phase 2; especially Video 50)</li>
  </ul>
  <p><a href="https://i.sstatic.net/xWUnY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xWUnY.png" alt="enter image description here" /></a></p>
  <h3>The code</h3>
  <p>The project file:</p>
  <ul>
  <li>the project's <code>SelfContained</code> property is set to <code>true</code></li>
  <li>the appsettings.json file <code>ExcludeFromSingleFile</code> property is set to <code>true</code></li>
  <li>the appsettings.[Environment].json files are added to gitignore.</li>
  </ul>
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;OutputType&gt;WinExe&lt;/OutputType&gt;
      &lt;TargetFramework&gt;net8.0-windows10.0.19041.0&lt;/TargetFramework&gt;
      &lt;Nullable&gt;enable&lt;/Nullable&gt;
      &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
      &lt;UseWPF&gt;true&lt;/UseWPF&gt;
      &lt;SelfContained&gt;True&lt;/SelfContained&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;CommunityToolkit.Mvvm&quot; Version=&quot;8.2.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Configuration&quot; Version=&quot;8.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.DependencyInjection&quot; Version=&quot;8.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Hosting&quot; Version=&quot;8.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Logging&quot; Version=&quot;8.0.0&quot; /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;ProjectReference Include=&quot;..\DevOpsWpf.Library\DevOpsWpf.Library.csproj&quot; /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;None Update=&quot;appsettings.Development.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;appsettings.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
        &lt;ExcludeFromSingleFile&gt;True&lt;/ExcludeFromSingleFile&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;appsettings.Production.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;appsettings.Staging.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;Documentations\AzureDevOpsSolution.docx&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;Documentations\ReadMe.txt&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update=&quot;Properties\launchSettings.json&quot;&gt;
        &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
    &lt;/ItemGroup&gt;
    
  &lt;/Project&gt;
  
  </code></pre>
  <p>The azure-pipeline file:</p>
  <ul>
  <li>task VSBuild@1 is currently disabled</li>
  <li>instead task DotNetCoreCLI@2 is enabled</li>
  </ul>
  <p>I can not figure out which arguments in DotNetCoreCLI@2 to use to accomplish my goal.</p>
  <pre class="lang-yml prettyprint-override"><code>trigger:
  - main
  
  pool:
    vmImage: 'windows-latest'
  
  # Check replacetokens-task and appsettings.json
  # the following variables are used in appsettings.json
  # applicationHomeDirectory
  # applicationName
  variables:
    solution: '**/*.sln'
    buildPlatform: 'Any CPU'
    runtimeId: 'win-x64'
    buildConfiguration: 'Release'
    applicationHomeDirectory: 'C:\DevOpsSolution'
    applicationName: 'Azur DevOps Solution (azure-pipelines.yml)'
  
  # not sure, if this is needed
  steps:
  - task: DeleteFiles@1
    displayName: 'Delete files in artifactstagingdirectory'
    inputs:
      SourceFolder: '$(build.artifactstagingdirectory)'
      Contents: '**'
  
  # working as intended
  - task: NuGetToolInstaller@1
    displayName: 'Use NuGet 6.8.0'
  
  # working as intended
  - task: NuGetCommand@2
    displayName: 'Restore NuGet Packages'
    inputs:
      restoreSolution: '$(solution)'
  
  # working as intended
  - task: qetza.replacetokens.replacetokens-task.replacetokens@5
    displayName: 'Replace tokens in appsettings.json'
    inputs:
      targetFiles: '**/*.json'
  
  # disabled task for testing
  - task: VSBuild@1
    displayName: 'Build solution'
    inputs:
      solution: '$(solution)'
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
    enabled: false
      
  # testing this task instead of VSBuild; in artifact there are tons of files, instead of one exe-file and one json-file
  - task: DotNetCoreCLI@2
    displayName: 'Publish'
    inputs:
      command: publish
      publishWebProjects: false
      arguments: '-c $(buildConfiguration) -r $(runtimeId) --self-contained true --output $(build.artifactstagingdirectory)'
      zipAfterPublish: false
    enabled: true
  
  # working as intended
  - task: VSTest@2
    displayName: 'Test solution'
    inputs:
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
  
  # working to publish it to SolutionDrop; not sure if this is all that needs to be done here
  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: SolutionDrop'
    inputs:
      PathtoPublish: '$(build.artifactstagingdirectory)'
      ArtifactName: SolutionDrop
    condition: succeededOrFailed()
  
  </code></pre>
  <p>The published artifact is &gt;200 MB and has a ton of files. That can not be correct. Here you see just the top:
  <a href="https://i.sstatic.net/dIt1b.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dIt1b.png" alt="enter image description here" /></a></p>
  
Tags: <azure-devops><azure-pipelines><azure-artifacts>
Title: How to setup a DotNetCoreCLI@2 task to publish a self-contained exe-file for a WPF project with .Net 8?
UserDisplayName: karwenzman
ThreadText: # How to setup a DotNetCoreCLI@2 task to publish a self-contained exe-file for a WPF project with .Net 8?
  
  (Asked by: username_0 on 2024-01-31)
  
  ### The settings
  
  My goal is to understand the CI/CD process on Azure (and in general). For that, I have build a little Wpf-App. It is not doing much. Just displaying a simple ReadMe.txt file.  
  A test project is included and the tests are running fine.  
  Also, I am practicing app-configuration by replacing placeholders in appsettings.json by varibles in azure-pipelines.yml. This is running as supposed.
  
  ### The goal to accomplish
  
  Now I am working on publishing a self-contained exe-file that is excluding appsettings.json. That is where I do need some help. **Is this task configured, properly?**
  
  ```yml
  - task: DotNetCoreCLI@2
    displayName: 'Publish'
    inputs:
      command: publish
      publishWebProjects: false
      arguments: '-c $(buildConfiguration) -r $(runtimeId) --self-contained true --output $(build.artifactstagingdirectory)'
      zipAfterPublish: false
    enabled: true
  
  ```
  
  ### References
  
  * [PublishAppsWithCli](https://learn.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli)
  * [AzurePipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops)
  * [TrainingCourse](https://www.youtube.com/playlist?list=PLLWMQd6PeGY0bEMxObA6dtYXuJOGfxSPx) (Phase 2; especially Video 50)
  
  [![enter image description here](https://i.sstatic.net/xWUnY.png)](https://i.sstatic.net/xWUnY.png)
  
  ### The code
  
  The project file:
  
  * the project's `SelfContained` property is set to `true`
  * the appsettings.json file `ExcludeFromSingleFile` property is set to `true`
  * the appsettings.[Environment].json files are added to gitignore.
  
  ```xml
  <Project Sdk="Microsoft.NET.Sdk">
  
    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
      <Nullable>enable</Nullable>
      <ImplicitUsings>enable</ImplicitUsings>
      <UseWPF>true</UseWPF>
      <SelfContained>True</SelfContained>
    </PropertyGroup>
  
    <ItemGroup>
      <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
      <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
    </ItemGroup>
  
    <ItemGroup>
      <ProjectReference Include="..\DevOpsWpf.Library\DevOpsWpf.Library.csproj" />
    </ItemGroup>
  
    <ItemGroup>
      <None Update="appsettings.Development.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="appsettings.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        <ExcludeFromSingleFile>True</ExcludeFromSingleFile>
      </None>
      <None Update="appsettings.Production.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="appsettings.Staging.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="Documentations\AzureDevOpsSolution.docx">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="Documentations\ReadMe.txt">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="Properties\launchSettings.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
    </ItemGroup>
    
  </Project>
  
  ```
  
  The azure-pipeline file:
  
  * task VSBuild@1 is currently disabled
  * instead task DotNetCoreCLI@2 is enabled
  
  I can not figure out which arguments in DotNetCoreCLI@2 to use to accomplish my goal.
  
  ```yml
  trigger:
  - main
  
  pool:
    vmImage: 'windows-latest'
  
  # Check replacetokens-task and appsettings.json
  # the following variables are used in appsettings.json
  # applicationHomeDirectory
  # applicationName
  variables:
    solution: '**/*.sln'
    buildPlatform: 'Any CPU'
    runtimeId: 'win-x64'
    buildConfiguration: 'Release'
    applicationHomeDirectory: 'C:\DevOpsSolution'
    applicationName: 'Azur DevOps Solution (azure-pipelines.yml)'
  
  # not sure, if this is needed
  steps:
  - task: DeleteFiles@1
    displayName: 'Delete files in artifactstagingdirectory'
    inputs:
      SourceFolder: '$(build.artifactstagingdirectory)'
      Contents: '**'
  
  # working as intended
  - task: NuGetToolInstaller@1
    displayName: 'Use NuGet 6.8.0'
  
  # working as intended
  - task: NuGetCommand@2
    displayName: 'Restore NuGet Packages'
    inputs:
      restoreSolution: '$(solution)'
  
  # working as intended
  - task: qetza.replacetokens.replacetokens-task.replacetokens@5
    displayName: 'Replace tokens in appsettings.json'
    inputs:
      targetFiles: '**/*.json'
  
  # disabled task for testing
  - task: VSBuild@1
    displayName: 'Build solution'
    inputs:
      solution: '$(solution)'
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
    enabled: false
      
  # testing this task instead of VSBuild; in artifact there are tons of files, instead of one exe-file and one json-file
  - task: DotNetCoreCLI@2
    displayName: 'Publish'
    inputs:
      command: publish
      publishWebProjects: false
      arguments: '-c $(buildConfiguration) -r $(runtimeId) --self-contained true --output $(build.artifactstagingdirectory)'
      zipAfterPublish: false
    enabled: true
  
  # working as intended
  - task: VSTest@2
    displayName: 'Test solution'
    inputs:
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
  
  # working to publish it to SolutionDrop; not sure if this is all that needs to be done here
  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: SolutionDrop'
    inputs:
      PathtoPublish: '$(build.artifactstagingdirectory)'
      ArtifactName: SolutionDrop
    condition: succeededOrFailed()
  
  ```
  
  The published artifact is >200 MB and has a ton of files. That can not be correct. Here you see just the top:
  [![enter image description here](https://i.sstatic.net/dIt1b.png)](https://i.sstatic.net/dIt1b.png)
  
  **Tags:** azure-devops, azure-pipelines, azure-artifacts
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-02-14. Score: 0 | Accepted answer
  
  Finally, I have received the result as it was intended to be.
  
  This [answer](https://stackoverflow.com/a/71239913/20737189) was the final clue. And I did find the reference in Microsoft [documentation](https://learn.microsoft.com/en-us/dotnet/core/deploying/).
  
  [![enter image description here](https://i.sstatic.net/QrCSH.png)](https://i.sstatic.net/QrCSH.png)
  
  These properties are set in the project file:
  
  ```xml
      <PublishSingleFile>true</PublishSingleFile>
      <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
  
  ```
  
  There was a [change](https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/runtimespecific-app-default) in the publish process by Microsoft. If PublishSingleFile is set to true, Self-Contained is implied automatically.  
  When the above properties are set in the project file, they do not need to be listed as arguments in the command line.
  
  The ***DotNetCoreCLI@2*** task looks like this:
  
  ```yaml
  steps:
  - task: DotNetCoreCLI@2
    displayName: 'Publish *.csproj'
    inputs:
      command: publish
      publishWebProjects: false
      projects: '**/DevOpsWpf.csproj'
      arguments: '-c Release -r win-x64 --output $(build.artifactstagingdirectory)'
      zipAfterPublish: false
  
  ```
  
  The ***project file*** looks like this:
  
  ```xml
  <Project Sdk="Microsoft.NET.Sdk">
  
    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
      <Nullable>enable</Nullable>
      <ImplicitUsings>enable</ImplicitUsings>
      <UseWPF>true</UseWPF>
      <PublishSingleFile>true</PublishSingleFile>
      <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
    </PropertyGroup>
  
    <ItemGroup>
      <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
      <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
    </ItemGroup>
  
    <ItemGroup>
      <ProjectReference Include="..\DevOpsWpf.Library\DevOpsWpf.Library.csproj" />
    </ItemGroup>
  
    <ItemGroup>
      <None Update="appsettings.Development.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="appsettings.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        <ExcludeFromSingleFile>True</ExcludeFromSingleFile>
      </None>
      <None Update="appsettings.Production.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="Documentations\ReadMe.txt">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="Properties\launchSettings.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
    </ItemGroup>
    
  </Project>
  
  ```
  
  
  ---
  
  