【问题标题】:Visual Studio Mac: Output obj / bin folder elsewhere not supported?Visual Studio Mac:不支持其他地方的输出 obj/bin 文件夹?
【发布时间】:2017-12-19 22:39:41
【问题描述】:

我有一个多项目解决方案,并希望将所有生成的 in/obj 工件放在另一个文件夹中。

我尝试设置:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugType>portable</DebugType>
    <OutputPath>..\Bin\Core\Debug\</OutputPath>
    <IntermediateOutputPath>..\Bin\Core\obj\</IntermediateOutputPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <OutputPath>..\Bin\Core\Release\</OutputPath>
    <IntermediateOutputPath>..\Bin\Core\obj\</IntermediateOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Library.fs" />
  </ItemGroup>

</Project>

但是:

  1. obj 文件夹仍会在原始位置重新创建。是 也在所需的位置,但为空。
  2. “恢复包”触发“1”而不是将它们放在所需位置
  3. 构建项目时,会填充 obj 文件夹。

这是版本:

Visual Studio Community 2017 for Mac 版本 7.3.2(内部版本 12)运行时: 单声道 5.4.1.7 (2017-06/e66d9abbb27)(64 位)

NuGet 版本:4.3.1.4445

.NET Core 运行时:/usr/local/share/dotnet/dotnet 最新版本 退出:2.0.0 SDK:/usr/local/share/dotnet/sdk/2.0.0/Sdks 版本 del SDK:2.0.0 SDK de MSBuild: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

【问题讨论】:

    标签: macos build visual-studio-mac


    【解决方案1】:

    此问题并非特定于 Visual Studio for Mac。如果您从命令行使用 dotnet,也会出现相同的行为。

    使用 Visual Studio for Mac 和 dotnet CLI,obj 目录在还原 NuGet 包时在项目目录中创建,并且仅包含还原生成的文件:

    • MyProject.csproj.nuget.cache
    • MyProject.csproj.nuget.g.targets
    • MyProject.csproj.nuget.g.props
    • project.assets.json

    在 ../Bin/Core/Debug 和 ../Bin/Core/obj 目录中创建构建文件。

    您可以通过设置 BaseIntermediateOutputPath 来获得您想要的行为。但是在项目文件本身中设置它可能会导致problems

    最简单的解决方案是在解决方案目录中创建一个 Directory.Build.props 文件,并在那里设置 BaseIntermediateOutputPath 属性。

    <Project>
      <PropertyGroup>
        <BaseIntermediateOutputPath>..\Bin\Core\obj\</BaseIntermediateOutputPath>
      </PropertyGroup>
    </Project>
    

    然后生成的NuGet还原文件会在你想要的目录下创建。

    Visual Studio for Mac 似乎仍然想在项目打开时在项目中创建一个空的 obj 目录,但是在还原或构建之后没有文件。

    【讨论】:

    • 很奇怪,但在设置 2 个项目后,它“工作”但在 \Bin 中创建另一个 netstandard2.0 文件夹,也在 \Bin\Core 中
    • 啊!如果路径末尾有“\”,就会发生这种情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 2013-12-05
    • 2011-07-15
    • 2021-09-13
    • 2010-11-08
    • 2017-03-16
    • 1970-01-01
    相关资源
    最近更新 更多