Open hin-hin opened 6 years ago
Thank you for posting this issue.
Confirmed still an issue and temporarily removing Directory.Build.props works.
Hi,
I can confim this issue with .NET SDK version 5.0.103 and dotnet-aspnet-codegenerator version 5.0.2. If you use build customization which will re-direct your binaries in a different directory, the dotnet-aspnet-codegenerator will produce the following error.
PS D:\git\project\src\SomeCsproj> dotnet aspnet-codegenerator -h
...
Scaffolding failed.
Failed to get Project Context for D:\git\project\src\SomeCsproj\SomeCsproj.csproj
...
Create file PS D:\git\project\Directory.Build.props
Content of this file must be:
PS D:\git\project> cat .\Directory.Build.props
<Project>
<PropertyGroup>
<_OutputPath>$(MSBuildThisFileDirectory)out\$(MSBuildProjectName)\</_OutputPath>
<BaseIntermediateOutputPath>$(_OutputPath)obj</BaseIntermediateOutputPath>
<BaseOutputPath>$(_OutputPath)bin</BaseOutputPath>
<ResultOutputPath>$(SolutionDir)out\</ResultOutputPath>
</PropertyGroup>
</Project>
After this, just do
I guess a lot of people out there are having this problem and do not know in the first place that it could be caused by their build customization. Therefore this might be worth a fix or maybe a better error message like. Please check if you are using build customization which is re-directing your build output or something like that.
I'm hitting this now when enabling the new artifacts directory:
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
For the docs on this .NET 8+ feature: https://learn.microsoft.com/en-us/dotnet/core/sdk/artifacts-output
I followed the instructions at https://www.natemcmaster.com/blog/2017/11/13/dotnet-watch-and-docker/ to setup docker with dotnet watch, which requires moving bin/ and obj/ out of the project folder using a Directory.Build.props file so that docker and Visual Studio Code can work together.
Then when I tried to run dotnet aspnet-codegenerator it failed with the following error (also an obj/ folder is created in the project):
If I remove the Directory.Build.props file then the code generator runs without error.
It seems that the tool does not read the settings inside Directory.Build.props and does not provide a way to specify the path to the obj/ folder (e.g. dotnet ef supports --msbuildprojectextensionspath).
Is there any other way to get the code generator to run other than removing Directory.Build.props?