【问题标题】:How to stop .net-core from continuously adding folders when building构建时如何阻止.net-core不断添加文件夹
【发布时间】:2019-10-10 01:26:39
【问题描述】:

每次构建 .NET Core 项目时,它都会在\bin\release 中添加一个包含.csproj 文件的更深的文件夹。结果是以下文件夹结构:

D:\home>
D:\home\site>
D:\home\site\repository>
D:\home\site\repository\bin>
D:\home\site\repository\bin\Release>
D:\home\site\repository\bin\Release\netcoreapp2.1>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin>
D:\home\site\repository\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release\netcoreapp2.1\bin\Release>

当执行更多构建时,这会继续增长。

在 Visual Studio 中,清理和重建有助于解决这个问题。几次构建后,文件名变得太长,在尝试运行应用程序时引发错误。

起初,这并不重要,但在将 WebApp-Bot 部署到 Azure 时,也会发生同样的情况。问题是我无法从服务器中删除过多的文件。这就是为什么我需要阻止它发生。

.csproj 文件:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <UserSecretsId>SOME_USER_SECRETS_ID</UserSecretsId>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="%2a%2a\**" />
    <Content Remove="%2a%2a\**" />
    <EmbeddedResource Remove="%2a%2a\**" />
    <None Remove="%2a%2a\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Gremlin.Net" Version="3.4.1" />
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.4.3" />
    <PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.4.3" />
    <PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.4.3" />
    <PackageReference Include="Microsoft.Recognizers.Text.DataTypes.TimexExpression" Version="1.1.6" />
  </ItemGroup>

  <Import Project="PostDeployScripts\IncludeSources.targets" Condition="Exists('PostDeployScripts\IncludeSources.targets')" />
  <Import Project="..\PostDeployScripts\IncludeSources.targets" Condition="Exists('..\PostDeployScripts\IncludeSources.targets')" />
  <ItemGroup>
    <None Remove="%2a%2a\%2a.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="bin\" />
  </ItemGroup>
  <ProjectExtensions><VisualStudio><UserProperties Properties_4launchSettings_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>

</Project>

我现在看到的includesources.targets 带有always 标志:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Compile Update="**\*.cs">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Compile>
    <None Include="**\*.csproj" >
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="PostDeployScripts\*.*" >
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

我想知道为什么会发生这种情况以及如何阻止它,欢迎所有帮助。

【问题讨论】:

  • 你能分享你的csproj吗?或者你可以在一个最小的项目中重新创建它吗?
  • 将文件添加到帖子中,大部分内容与 Microsoft 的 Webapp-Bot 示例中的内容相同
  • 我感觉是这部分:&lt;ItemGroup&gt;&lt;Folder Include="bin\" /&gt;&lt;/ItemGroup&gt; 可能告诉 MSBuild 包含 bin 目录,该目录已经包含发布目录,然后将包含另一个 bin 目录,它将.. ..如果你赶上我的漂移
  • IncludeSources.targets 包含什么?
  • @JamieTaylor &lt;Folder&gt; items 只告诉 VS 显示文件夹,即使它是空的。

标签: visual-studio azure .net-core botframework azure-web-app-service


【解决方案1】:

您的includesources.targets 文件中有这个小宝石:

<Compile Update="**\*.cs">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>

如果我理解正确,这会导致 .cs 文件被复制到您的输出文件夹中。下次触发构建时,这些文件可能也会被编译,从该位置创建一个新的bin\Release\netcoreapp2.1

我不完全确定目标文件的用途,但我很确定它会导致这个问题。尝试从您的 .csproj 中删除该文件及其对它的引用,重新构建您的项目,看看您是否可以部署该机器人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 2018-05-30
    • 1970-01-01
    相关资源
    最近更新 更多