How to pass a variable from one project to another project C#

Solution for How to pass a variable from one project to another project C#
is Given Below:

I have a static variable inside of my main project (mvc), I am wanting to be able to pass/use that variable in my other project (asp.net core 5.0 web api) project. I was reading up on how you can perform this task, one of the ways is using a static variable which I have. I read this post and one of the solutions mentions you can call that static variable from the first project into the other project by calling the namespace of that first project in the first project. However, when I do so it does not let me it says it does not exist. Is there a way to be able to do this?

On the post their example was:

using System.Windows.Forms;

namespace Demo1
{
    public class Sample1
    {
        public static string x = "initial value of 'x";

        public void sampleFn1() {x = "value of 'x set in function";}
    }
}

namespace Demo2
{
    public class Sample2
    {
        public void sampleFn2(){MessageBox.Show(Demo1.Sample1.x);}
    }
}

For me, Project 1 is CustomerApp and Project 2 is Service.Api:

namespace CustomerApp.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        public static Guid uniqueId = Guid.NewGuid();

    }

}

Then in my ServiceApi I tried performing the same as the example from the post, but when I call the namespace CustomerApp it does not give me any options to reference it to the other project. Is there a specific using I need to use in order to replicate the example from the post?

namespace Service.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly ILogger<ValuesController> _logger;

        public ValuesController(ILogger<ValuesController> logger)
        {
            _logger = logger;
        }

        // GET: api/<ValuesController>
        [HttpGet]
        [Route("sample")]
        public ActionResult Get()
        {
            _logger.LogInformation("Target method invoked.....{@CorrelationId}", CustomerApp.); // here I am trying to perform CustomerApp.Controllers.HomeController.uniqueId.ToString()
        }
    }
}

I think you forgot to add the project reference to destination project where you want to use the variable ,
Add reference like this :

right-click on your destination project and select Add > Project Reference

enter image description here

and in final choose the variable project

enter image description here

this will help you

You will want to make sure that the static variable is defined in a Class Library project, and that the Web project has a reference to the Class Library project.

The way your code is currently constructed, it looks like both projects are web projects (your first project mentions the HomeController). As much as possible, avoid this type of co-mingling. Move business logic into the class library, and keep the web logic in the web project.

first, if you haven’t, add it to the HomeController class (using CustomerApp.Controllers.HomeController;). Your own example does not match the example you reference. In the first example, a static variable is used between two different classes in the same namespaces, but in your example you are trying to operate between different namespaces and different classes.
So if your service is inside your main project you should add.

then you can use it as below.

public ActionResult Get()
        {
            _logger.LogInformation("Target method invoked.....{@CorrelationId}", HomeController.uniqueId.ToString()); 
        }