Open stachu99 opened 6 years ago
@livarcocc - is this also an SDK issue? In general, I don't think these are reliably set in command line builds anyway, so it's probably best not to depend on them...
The SDK does not set these properties. It is set somewhere else I believe.
@nguerrera can you check?
@stachu99 my guess is that this is related to https://github.com/dotnet/project-system/issues/2982. In the case where they are undefined, it's because they are being launched by the dependency from "dotnet publish" to build, but outside of the IDE, these variables are not set.
cc @mlorbetske A publish initiated from VS should have the same properties as a build initiated by VS. I have seen that publish does not do this for SolutionDir and it actually triggers different behavior in the SDK resolver. If that's what's happening here, I think the VS code that kicks of publish should be changed to match how VS kicks off build.
@vijayrkn
What's going on with this issue...?
Ping, @vijayrkn This seems to be an issue with Publish in VS not setting the same properties on build as a regular build.
We do pass all the properties that we get from the project system during publish. I see that this issue was created an year before. Does this still happen?
You definitely don't get things like $(SolutionDir)
when doing dotnet build
or dotnet publish
in my experience. It would be super great if dotnet
and Visual Studio were unified.
You should get $(SolutionDir) and the like on the command line if you are building a .sln, but not if you are building an individual project. Projects don't know what solution they are in and they could be in more than one so there's no real way to make that just work if you are operating on a single project on the command line.
Tested on MS VS 2017 Community 2017, version 15.4.4, MS .NET Framework 4.7.02046.
A part of the code in .csproj:
There are targets with events executed after targets: BeforePublish, AfterPublish and used macros are not defined during publish.
On a publish output are undefined macros: $(DevEnvDir), $(SolutionFileName), $(SolutionPath), $(SolutionDir), $(SolutionName), $(SolutionExt). These macros are undefined only while publish is executed. These macros are defined and work fine while a build is executed and in .csproj are targets with an option AfterTarget and targets BeforeBuild, PreBuildEvent, PostBuildEvent, AfterBuild. Other targets like $(OutDir), $(ProjectPath), $(ProjectName) are defined and work fine in publish and build. Isn't macros be defined during publish as during build?