DotnetCore项目IntermediateOutputPath将一些文件保留在解决方案目录中 [英] DotnetCore project IntermediateOutputPath leaves some files in the solution directory

查看:492
本文介绍了DotnetCore项目IntermediateOutputPath将一些文件保留在解决方案目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了保持存储库的清洁并与输出文件和构建文件分开,我们更改了项目文件中的相应路径。

In order to keep the repository clean and separated from output and build files we change corresponding paths in the project file.

对于Net Framework项目,请指定 IntermediateOutputPath 将obj目录重定向到相应的文件夹。

For Net Framework project specifying IntermediateOutputPath redirects the obj directory to the corresponding folder.

对于Net Core项目(3.0),使用此属性是不够的。尽管Debug,Release文件夹确​​实已重定向,但 obj 文件夹仍会创建,并且其中包含一些文件-例如
project.assets.json,.csproj.nuget.cache, .csproj.nuget.dgspec.json,.csproj.nuget.g.props,.csproj.nuget.g.targets
使用 BaseIntermediateOutputPath -也不起作用。

For Net Core project (3.0) using this property is not sufficient. Whereas Debug, Release folders are indeed redirected, the obj folder is still created and it contains some file - such as project.assets.json, .csproj.nuget.cache, .csproj.nuget.dgspec.json,.csproj.nuget.g.props, .csproj.nuget.g.targets . Using BaseIntermediateOutputPath - doesnt help either.

只是想知道是否有人可以建议如何移动整个obj目录?
谢谢

Just wonder if someone can suggest how to move the whole obj directory? Thanks

马丁建议的解决方案在Net Core项目中效果很好

The Solution suggested by Martin works fine for Net Core projects

<Project>
  <PropertyGroup>
    <BuildDIrectory>C:\Temp\Build\$(Configuration)</BuildDIrectory>
    <RelativePath>some arelative path which depends on location of corresponding project withing the solution</RelativePath>

    <BaseIntermediateOutputPath>$(BuildDIrectory)\obj\$(RelativePath)\$(AssemblyName)\</BaseIntermediateOutputPath>
    <OutputPath>$(BuildDIrectory)\out\$(RelativePath)\$(AssemblyName)\</OutputPath>
    <DocumentationFile>$(BuildDIrectory)\Documentation\$(RelativePath)\$(AssemblyName).xml</DocumentationFile>
  </PropertyGroup>

  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

  ...
  </Project>


推荐答案

BaseIntermediateOutputPath 也可以,但是必须尽早设置才能生效。

BaseIntermediateOutputPath works as well, but it needs to be set very early in order to take effect.

最简单的方法是将其添加到 Directory.Build.props 文件中:

The easiest way would be to add it to a Directory.Build.props file:

<Project>
  <PropertyGroup>
    <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\shared-obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>

如果要直接在csproj文件中指定,则不能使用< Project Sdk = 表示法,因为需要在应用SDK的某些部分之前设置该属性。但是,在使用显式SDK导入并正确排序时,该属性才有效:

If you want to specify it directly in the csproj file, you cannot use the <Project Sdk=" notation since the property needs to be set before parts of the SDK are applied. However it works when using explicit SDK imports and correct ordering:

<Project>

  <PropertyGroup>
    <BaseIntermediateOutputPath>..\shared-obj\myprojA\</BaseIntermediateOutputPath>
  </PropertyGroup>

  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

</Project>

这篇关于DotnetCore项目IntermediateOutputPath将一些文件保留在解决方案目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆