1

I have the following issue.

I've created an Azure function and want to run a compiler stored in {ProjectFile}/AlCompiler folder.

The folder contains .dll's and alc.exe file. The exe-file requires these .dll's to run, otherwise produces an error.

I tried to publish the files of AlCompiler folder to wwwroot directory adding following to the .csproj project file:

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

Also I tried this markup:

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

And tried to use <Link> attribute:

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

All of these causes the files of AlCompiler directory being split up on publish:

  • exe and some other files go to wwwroot/AlCompiler folder
  • all the .dll's go to wwwroot/bin/AlCompiler folder

I didn't find any way to keep them in one place.

So I cannot run alc.exe file due to .dll's being missing.

I'd be very glad for your help with this!

2 Answers2

0

You should use below code in your .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>

For more details, you can see my answer in below post.

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

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Thanks for a reply. For now I came out with my own solution that works. Will try to check out yours. – Andrii Diachenko May 13 '21 at 09:19
  • @AndriiDiachenko Okay, I'm glad you solved the problem. My method can also be solved. If you are interested, you can try it. – Jason Pan May 13 '21 at 09:20
  • @AndriiDiachenko If you think it is useful, could you mark my answer as [accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) , Tks~ , you also can post your solutions as answer to help more forum user. – Jason Pan May 13 '21 at 09:21
  • your method doesn't work for dlls - they are still copied to the bin/your_folder/yourfile folder instead of your_folder/yourfile. For other extensions it seems to work (I tried for .json and .exe files). Is there some additional xml attribute/property to override this behavior for dlls? – undermind May 16 '22 at 14:34
0

I've came across the solution, just doing things vice versa.

Instead of trying to add .dll's to Compiler folder (where .exe is stored), I add .exe's to bin folder (where .dll's are stored).

Don't know if it's the best solution but it works:

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