Using Visual Studio 2017, in the solution explorer, I right-click on a C# .Net Core project and select "Publish...". I create a publish profile that publishes the app to a folder or file share. The result is a profile whose default target location is an absolute path "[project directory]\bin\Release\netcoreapp2.1\publish\", such as in the following snippet.
Visual Studio generates a .pubxml file to store that publish profile, where the target location is stored in a <PublishDir> tag. For example:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PublishDir>F:\work\foo\bin\Release\netcoreapp2.1\publish\</PublishDir>
</PropertyGroup>
</Project>
What I would prefer is to use a variable in the value of the <PublishDir> tag, such as the $(SolutionDir) variable. I can manually edit the .pubxml file to inject a variable. For example:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<PublishDir>$(SolutionDir)\publish\</PublishDir>
</PropertyGroup>
</Project>
However, when I next load the project in Visual Studio, that variable is either ignored, or has a empty value, such as in the following snippet.
Is there a way to use variables in the publish profile?


Had a similar problem using VS2019. Only things that worked for me where environment variables like
$(windir)and Properties in thepubxmlabove the line where they are needed e.g.The resulting PublishUrl was
WebPublishMethodis not part ofPublishUrlbecause it's belowPublishUrl.Don't know about
F:\work\foo\bin\but you could try Configuration andTargetFrameworkforRelease\netcoreapp2.1