Mobz
Mobz

Reputation: 374

Azure Function create folders in the bin-folder?

I have an azure function (v3):

    [FunctionName("Function1")]
    public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ExecutionContext context)
    {
        if (File.Exists(Path.Combine(context.FunctionAppDirectory, "bin", "MyFolder", "TextFile1.txt")))
            return new OkObjectResult("File does exists!");
        else
            return new OkObjectResult("File does NOT exists!");
    }

Inside my .csproj is have:

<None Update="MyFolder\TextFile1.txt">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

and this:

<Target Name="CopyFiles" AfterTargets="AfterBuild">

<ItemGroup>
  <MySourceFiles Include="$(OutDir)\MyFolder\TextFile1.txt" />
</ItemGroup>

<Copy SourceFiles="@(MySourceFiles)" DestinationFolder="$(OutDir)\bin\MyFolder\" SkipUnchangedFiles="true" />
</Target>

I want ..MyFolder/TextFile1.txt to be copied to ..bin/MyFolder/TextFile1.txt

Running this locally it works fine File does exists! But publishing it to Azure i get a File does NOT exists!

Looking at the .scm.azurewebsites.net/DebugConsole I can see the folders are not quite as I had hope

C:\home\site\wwwroot\MyFolder>
C:\home\site\wwwroot\bin>

I did try to add the <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> but that didn't help.

How can I make this example work?

(EDIT) Why I try to do this: I have a third-party DLL that expect a folder-structure located in the same folder as the DLL is located. This is normally stretch forward in a .NET project. Using Azure functions this folder-structure is now not placed in the same folder as the DLL.

Upvotes: 2

Views: 2383

Answers (1)

Harshita Singh
Harshita Singh

Reputation: 4870

You have to make the file as Copy Always:

<None Update="MyFolder\TextFile1.txt">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

In VS, Click on the file > Properties > Change Copy to Output Directory > Copy Always.


Edit:

In this case, you will have to copy file from wwwroot folder to wwwroot/bin using Pipeline Copy file task.

Upvotes: 3

Related Questions