Visual Studio 将 .dll 复制到发布时的 Bin 文件夹
Visual Studio copies .dll's to Bin folder on Publish
我有以下问题。
我已经创建了一个 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>
并尝试使用 <Link>
属性:
<ItemGroup>
<Content Include="AlCompiler/**">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<Link>AlCompiler\%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>
所有这些导致 AlCompiler 目录的文件在发布时被拆分:
- exe 和一些其他文件转到 wwwroot/AlCompiler 文件夹
- 所有 .dll 转到 wwwroot/bin/AlCompiler 文件夹
我没有找到任何方法将它们放在一个地方。
所以我无法 运行 alc.exe 文件,因为缺少 .dll。
我很高兴能得到你的帮助!
您应该在 .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>
详情请看我下面的回答post。
我找到了解决方案,只是反之亦然。
我没有尝试将 .dll 的 添加到编译器文件夹(其中存储了 .exe),而是添加了 .exe的到bin文件夹(存储.dll的)。
不知道这是否是最佳解决方案,但它有效:
<ItemGroup>
<ContentWithTargetPath Include="AlCompiler/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<TargetPath>bin\AlCompiler\%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
</ContentWithTargetPath>
</ItemGroup>
我有以下问题。
我已经创建了一个 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>
并尝试使用 <Link>
属性:
<ItemGroup>
<Content Include="AlCompiler/**">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<Link>AlCompiler\%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>
所有这些导致 AlCompiler 目录的文件在发布时被拆分:
- exe 和一些其他文件转到 wwwroot/AlCompiler 文件夹
- 所有 .dll 转到 wwwroot/bin/AlCompiler 文件夹
我没有找到任何方法将它们放在一个地方。
所以我无法 运行 alc.exe 文件,因为缺少 .dll。
我很高兴能得到你的帮助!
您应该在 .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>
详情请看我下面的回答post。
我找到了解决方案,只是反之亦然。
我没有尝试将 .dll 的 添加到编译器文件夹(其中存储了 .exe),而是添加了 .exe的到bin文件夹(存储.dll的)。
不知道这是否是最佳解决方案,但它有效:
<ItemGroup>
<ContentWithTargetPath Include="AlCompiler/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<TargetPath>bin\AlCompiler\%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
</ContentWithTargetPath>
</ItemGroup>