Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Pipelines Build Error #138

Open
RacerDelux opened this issue Dec 4, 2024 · 6 comments
Open

Azure Pipelines Build Error #138

RacerDelux opened this issue Dec 4, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@RacerDelux
Copy link

RacerDelux commented Dec 4, 2024

Describe the bug
When running Azure Pipelines and building in Release mode, I get the following error:
There was an error exporting the HTTPS developer certificate to a file. Please create the target directory before exporting. Choose permissions carefully when creating it.

To Reproduce
Set up a build pipeline with a project using Vite.AspNetCore. In this case I used the example MVC project.

Expected behavior
For the built to complete. Since I am targeting Release, it shouldn't even be asking for a HTTPS developer certificate.

Screenshots
image

Device (please complete the following information):

  • OS: Windows
  • IDE/Editor: Azure Pipelines

Additional context
This is my build task in Cake:

var configuration = Argument<string>("configuration", "Release");
Task("Build")
	.IsDependentOn("Clean")
	.IsDependentOn("Restore")
	.Does(() =>
	{
		var buildSettings = new DotNetBuildSettings();
		buildSettings.NoRestore = true;
		buildSettings.Configuration = configuration;
		buildSettings.Verbosity = DotNetVerbosity.Detailed;

		DotNetBuild(solutionPath, buildSettings);
	});
@RacerDelux RacerDelux added the bug Something isn't working label Dec 4, 2024
@Eptagone
Copy link
Owner

Eptagone commented Dec 4, 2024

Hi, are you validating the environment before run app.UseViteDevelopmentServer()?
That method shouldn't be called in production.

@RacerDelux
Copy link
Author

RacerDelux commented Dec 4, 2024

Hi, are you validating the environment before run app.UseViteDevelopmentServer()? That method shouldn't be called in production.

This is what is in my program.cs:

if (app.Environment.IsDevelopment())
{
    app.UseWebSockets();
    // Use Vite Dev Server as middleware.
    app.UseViteDevelopmentServer(true);
}

And this is my Environment setting in the pipeline:
image

It looks like the error comes right after these NPM scripts are run.
image

@Eptagone
Copy link
Owner

Eptagone commented Dec 5, 2024

Ahh. I was thinking you were running the Vite dev server but it's not that.
You're creating a HTTPS certificate in your vite.config.ts like the examples. That's okey while you are developing the app, but it's not even required for production and as I see your pipeline process doesn't allow to create the certificate anyway.
So, the solution is editing your vite.config.ts to avoid generating the dotnet certificate in production mode and/or remove all of the SSL configuration for Vite.

@RacerDelux
Copy link
Author

Ahh. I was thinking you were running the Vite dev server but it's not that.

You're creating a HTTPS certificate in your vite.config.ts like the examples. That's okey while you are developing the app, but it's not even required for production and as I see your pipeline process doesn't allow to create the certificate anyway.

So, the solution is editing your vite.config.ts to avoid generating the dotnet certificate in production mode and/or remove all of the SSL configuration for Vite.

Don't I need that for development? If so is it possible to pass through the environment variable and skip making the cert?

@Eptagone
Copy link
Owner

Eptagone commented Dec 5, 2024

The certificate is only required if you want/need to use https for both ASP.NET and Vite during development and use the same dev certificate. If that's not the case, you can work without SSL.

And as you said, you can also use environment variables to skip the cert in your vite.config.ts by reading the environment variable via process.env.MY_VARIABLE.

@RacerDelux
Copy link
Author

And as you said, you can also use environment variables to skip the cert in your vite.config.ts by reading the environment variable via process.env.MY_VARIABLE.

This worked great! Do you think it would be good to update the example to have this logic already? Could be useful.
This is the modified code at the beginning of the defineConfig function:

// Ensure the certificate and key exist
if (process.env.ASPNETCORE_ENVIRONMENT === 'Development' && (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath))) {
      // Make the cert folder if missing
      if (!fs.existsSync(baseFolder))
          fs.mkdirSync(baseFolder);

Not sure if there is a downside, but I changed the cert path to:

const baseFolder =
    `${process.env.PWD}/.certs`;

This helps get around permission issues when making the directory if it doesn't exist (something that has to be manually fixed when running the original example on OSX)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants