vs中怎么设置统一的output路径

背景:
1、一个sln下有多个csproj项目,让所有csproj生成的dll路径在sln根目录下的ouput文件夹
解决办法:
1、在sln目录下新建Directory.Build.props文件,文件内容如下:

 <Project>
    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
        <CustomOutputPath>$(SolutionDir)output\Debug\</CustomOutputPath>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
        <CustomOutputPath>$(SolutionDir)output\Release</CustomOutputPath>
    </PropertyGroup>
</Project>

2、编辑csproj文件,使 $(CustomOutputPath),其中$(CustomOutputPath)就是Directory.Build.props定义的内容(支持条件判断)。
示例如下

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>$(CustomOutputPath)</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>$(CustomOutputPath)</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

3、重新加载csproj项目,或者重新打开VS,重新生成即可。

posted @ 2024-06-03 15:05  Bonker  阅读(7)  评论(0编辑  收藏  举报