I'm trying to build my project from dotnet CLI.
I'm using dotnet build and it fails.
How to reproduct:
Create a simple console application using Visual Studio template
Add a file named
Colors.txtto the solution directoryAdd a file named
Names.txtto the project directoryModify
csprojfile to include apost-buildevent<PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <Target Name="CopySettingsToOutput" AfterTargets="PostBuildEvent"> <Exec Command="copy $(ProjectDir)\Names.txt $(TargetDir)\Names.txt" /> <Exec Command="copy $(SolutionDir)\Colors.txt $(TargetDir)\Colors.txt" /> </Target>Now build using Visual Studio (it gets built)
Now build using
dotnet buildcommand and it fails. It says:
error MSB3073: The command "copy Undefined\Colors.txt C:\---path---\Colors.txt" exited with code 1.
Why $(SolutionDir) is undefined when using dotnet build?