1

I have a app running on .NET 6.

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net6.0-windows</TargetFramework>

In this project I have dlls which I wanna copy from libraries folder files to output folder. I am using the below but its worrking,

<Target Name="AfterBuild" >
    <ItemGroup>
        <_CopyItems Include="Libraries\*.*" />
    </ItemGroup>
  <Copy SourceFiles="@(_CopyItems)" DestinationFolder="$(BuildOutput)" />
</Target>

Complete file is below,

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net6.0-windows</TargetFramework>
      <UseWindowsForms>true</UseWindowsForms>
      <Nullable>enable</Nullable>
      <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>


    <Target Name="AfterBuild" >
        <ItemGroup>
            <_CopyItems Include="Libraries\*.*" />
        </ItemGroup>
      <Copy SourceFiles="@(_CopyItems)" DestinationFolder="$(BuildOutput)" />
    </Target>

    <ItemGroup>
        <Reference Include="Lib">
            <HintPath>Libraries\Lib.dll</HintPath>
        </Reference>
    </ItemGroup>
</Project>
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
  • 1
    I don't think there is a standard property with the name `$(BuildOutput)` and your project file is not defining such a property. If the intent is to copy to the project's output directory, then the property you want to use is named `OutDir`. e.g. ``. See [Common MSBuild project properties](https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2022) – Jonathan Dodds Mar 01 '23 at 14:46

1 Answers1

1

I wanna copy from libraries folder files to output folder

I have a work demo like below, you can try it(I copy the ExampleJsInterop.cs file from RazorClassLibrary1 to output folder). Besides, hope this will help.

1.Double-click the project name,edit the file like below:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
    <ItemGroup>
        <Content Include="..\RazorClassLibrary1\ExampleJsInterop.cs" Link="ExampleJsInterop.cs">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
    </ItemGroup>
</Project>

2.Rebuild, I will see ExampleJsInterop.cs is copy to the project

enter image description here

  1. Publish to folder enter image description here
Qing Guo
  • 6,041
  • 1
  • 2
  • 10