dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.35k stars 345 forks source link

AspireHost doesn't seem to respect some MSBuild properties? #4643

Open En3Tho opened 5 days ago

En3Tho commented 5 days ago

Recently I've been migrating my personal projects to use artifacts output with my custom provided path:

Here is what I've added to my Directory.Build.props:

<PropertyGroup>
        <UseArtifactsOutput>true</UseArtifactsOutput>
        <ARTIFACTS_PATH_DOTNET Condition=" '$(ARTIFACTS_PATH_DOTNET)' == '' ">$(MSBuildThisFileDirectory)artifacts</ARTIFACTS_PATH_DOTNET>
        <ARTIFACTS_PATH_DOTNET Condition=" '$(ARTIFACTS_PATH_DOTNET)' != '' ">$(ARTIFACTS_PATH_DOTNET)\$(SolutionName)</ARTIFACTS_PATH_DOTNET>
        <ArtifactsPath>$(ARTIFACTS_PATH_DOTNET)</ArtifactsPath>
    </PropertyGroup>

When build is done artifacts are published to folder I've chosen in ARTIFACTS_PATH_DOTNET env variable for example: ARTIFACTS_PATH_DOTNET\MySolution\bin\MyApp\debug - this is expected

But when I start app host it seems to miss SolutionName and start process like this and fails: 'ARTIFACTS_PATH_DOTNET\bin\MyApp\debug\MyApp.exe'

What can I do to fix this? I can obviosuly replace $(SolutionName) with a concrete one but it is not ideal I guess.

En3Tho commented 5 days ago

I've fixed this by adding to the Directory.Build.props but as I said it is not ideal. Is there a way for AppHost to get this value automatically?

<SolutionName Condition=" '$(SolutionName)' == ''">MyApp</SolutionName>
davidfowl commented 3 days ago

@joperezr @eerhardt can one of you take a look?

eerhardt commented 3 days ago

@En3Tho, the easiest way for us to investigate is if you can provide a repro project that reproduces the behavior. This can either be a .zip file or a link to a github repo. Is that possible?

En3Tho commented 3 days ago

@eerhardt The issue turned out to be slightly trickier (the build/run part)

  1. Create new aspire-starter application

    dotnet new aspire-starter -o "AspireApp"
    cd .\AspireApp\
  2. Create Directory.Build.props file

    dotnet new buildprops
    Copy the following into Directory.Build.props:
    <Project>
    <PropertyGroup>
        <UseArtifactsOutput>true</UseArtifactsOutput>
        <ArtifactsPath>$(MSBuildThisFileDirectory)artifacts\$(SolutionName)</ArtifactsPath>
    </PropertyGroup>
    </Project>
  3. Run restore/build

    dotnet restore
    dotnet build

Now here is tricky part:

  1. artifacts\AspireApp\bin|obj folder should appear when dotnet restore/build is executed from folder with a solution file. This is a correct location for generated artifacts.
  2. If same commands are executed from project folder then there is no SolutionName and bin|obj are created in \artifacts. This is not a correct location.
  3. This behavior results in dotnet run / dotnet run --project creating files in incorrect location but app actually runs.
  4. But if I run from the ide it seems to be doing a solution-like build and then run generated .exe from correct location. This fails.