【问题标题】:Visual Studio copies .dll's to Bin folder on PublishVisual Studio 将 .dll 复制到发布时的 Bin 文件夹
【发布时间】:2021-07-22 00:03:32
【问题描述】:

我有以下问题。

我创建了一个 Azure 函数,并希望运行存储在 {ProjectFile}/AlCompiler 文件夹中的编译器。

文件夹包含.dll的alc.exe文件。 exe 文件需要这些 .dll 的 才能运行,否则会产生错误。

我尝试将 AlCompiler 文件夹的文件发布到 wwwroot 目录在 .csproj 项目文件中添加以下内容:

<ItemGroup>
    <Content Include="AlCompiler/**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemGroup>

我也试过这个标记:

<ItemGroup>
    <ContentWithTargetPath Include="AlCompiler/**">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      <TargetPath>AlCompiler\%(Filename)%(Extension)</TargetPath>
    </ContentWithTargetPath>
</ItemGroup>

并尝试使用&lt;Link&gt;属性:

<ItemGroup>
    <Content Include="AlCompiler/**">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      <Link>AlCompiler\%(Filename)%(Extension)</Link>
    </Content>
</ItemGroup>

所有这些都会导致 AlCompiler 目录的文件在发布时被拆分:

  • exe 和其他一些文件转到 wwwroot/AlCompiler 文件夹
  • 所有 .dll 都转到 wwwroot/bin/AlCompiler 文件夹

我没有找到任何方法将它们保存在一个地方。

由于 .dll 丢失,我无法运行 alc.exe 文件。

如果您能在这方面提供帮助,我将非常高兴!

【问题讨论】:

    标签: c# azure visual-studio dll azure-functions


    【解决方案1】:

    您应该在.csproj 中使用以下代码。

    <ItemGroup>
        <ResolvedFileToPublish Include="your_folder/yourfile">
        <RelativePath>your_folder/yourfile</RelativePath>
        </ResolvedFileToPublish>
        <ResolvedFileToPublish Include="azure-functions-host/appsettings.prod.json">
        <RelativePath>azure-functions-host/appsettings.prod.json</RelativePath>
        </ResolvedFileToPublish>
        <ResolvedFileToPublish Include="azure-functions-host/appsettings.dev.json">
        <RelativePath>azure-functions-host/appsettings.dev.json</RelativePath>
        </ResolvedFileToPublish>
    </ItemGroup>
    

    更多详情,您可以在下面的帖子中看到我的回答。

    1. Azure Functions don't publish appsettings.prod.json file

    2. Unable to find files located in my root project folder when hosted on Azure

    【讨论】:

    • 感谢您的回复。现在我提出了我自己的有效解决方案。将尝试检查您的。
    • @AndriiDiachenko 好的,很高兴你解决了这个问题。我的方法也可以解决。有兴趣的可以试试。
    • @AndriiDiachenko 如果你觉得有用,可以把我的回答标记为accepted,Tks~,你也可以将你的解决方案发布为帮助更多论坛用户的答案。
    【解决方案2】:

    我遇到了解决方案,反之亦然。

    我没有尝试将 .dll's 添加到 Compiler 文件夹(其中存储 .exe),而是将 .exe's 添加到 bin 文件夹( .dll 的存储位置)。

    不知道这是否是最好的解决方案,但它有效:

    <ItemGroup>
        <ContentWithTargetPath Include="AlCompiler/**">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
          <TargetPath>bin\AlCompiler\%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
        </ContentWithTargetPath>
    </ItemGroup>
    

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多