2

I have a simple ASP.NET Core React JS web app. I've been publishing it directly to Azure just fine.

Recently I introduced a 2nd environment (prod vs dev).

How can I publish it to Prod using .env, and publish to Dev using .env.dev ?

Notes:

  • I build using VS Enterprise.
  • I deploy using VS Enterprise (right-click -> Publish).
  • I know I can update the 'scripts' section in packages.json. But I dont believe this script(s) are called when I do a Publish from VS IDE.

Perhaps there is a way to specify the script??

Ex: build:dev would build using .env.development, and build:prod would build using .env

Thanks

Update

I found this in the .csproj file:

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)build\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140
  • if I'm understanding correctly it seems that you're wanting to do what Azure DevOps, Microsoft CI/CD pipeline does, want artifact in the testing stage, after testing completes, passes all test (or approve) move to staging the then to production (again upon approval). My example differ from yours. – MZM Dec 11 '22 at 02:36
  • Your note poin 3, yes your 'scripts' section in packages.json will called when you do a publish. Command="npm run build" will call it. Try to modify your package.json. – Arnas Dec 11 '22 at 15:32
  • I was able to find a solution. Simpler than I thought. Basically i added new a publish profile, which modifies the .csproj. Here is where the build and publish settings can be configured. – AlvinfromDiaspar Dec 14 '22 at 17:07

0 Answers0