繁体   English   中英

Visual Studio 将.dll 复制到发布时的 Bin 文件夹

[英]Visual Studio copies .dll's to Bin folder on Publish

我有以下问题。

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

该文件夹包含.dllalc.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>

并尝试使用<Link>属性:

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

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

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

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

因此,由于缺少.dll,我无法运行 alc.exe 文件。

我会很高兴你在这方面的帮助!

您应该在.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函数不发布appsettings.prod.json文件

2. 托管在 Azure 上时,找不到位于我的根项目文件夹中的文件

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

而不是试图添加。 dll到编译器文件夹(存储.exe的位置),我添加。 exe到 bin 文件夹(存储.dll 的位置)。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM