DotnetCore project IntermediateOutputPath leaves some files in the solution directory

依然范特西╮ 提交于 2020-03-03 06:11:47

问题


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

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

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.

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

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>

回答1:


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

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

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

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>


来源:https://stackoverflow.com/questions/57901969/dotnetcore-project-intermediateoutputpath-leaves-some-files-in-the-solution-dire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!