$(SolutionDir)变量可以在Visual Studio Publish Profile中使用吗?

发布于 2025-02-04 09:47:56 字数 1686 浏览 2 评论 0原文

使用Visual Studio 2017,在解决方案资源管理器中,我右键单击C#.NET核心项目,然后选择“发布...”。我创建一个发布个人资料,将应用程序发布到文件夹或文件共享。结果是一个配置文件,其默认目标位置是绝对路径“ [Project Directory] ​​\ bin \ Release \ netCoreApp2.1 \ Publish \”,例如在以下片段中。

Visual Studio生成.pubxml文件以存储该发布配置文件,其中目标位置存储在< lt; lt; prublishdir>中标签。例如:

<?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>

我希望是在&lt; PublishDir&gt;标签的值中使用一个变量,例如$(solutiondir)变量。我可以手动编辑.pubxml文件以注入变量。例如:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
    <PublishDir>$(SolutionDir)\publish\</PublishDir>
  </PropertyGroup>
</Project>

但是,当我下一个将项目加载到Visual Studio中时,该变量要么被忽略,要么具有空值,例如在以下片段中。

有没有办法在发布配置文件中使用变量?

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 2017 Publish Profile Settings dialog

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.

enter image description here

Is there a way to use variables in the publish profile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2025-02-11 09:47:56

使用VS2019也有类似的问题。只有对我有用的东西,环境变量之类的环境变量(例如$(windir))以及pubxml上方的属性中的属性,其中需要的

<!-- removed some properties from xml -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <PublishProvider>FileSystem</PublishProvider>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <PublishUrl>$(WINDIR)\$(PublishProvider)\$(WebPublishMethod)\$(LastUsedBuildConfiguration)_$(TargetFramework)</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
  </PropertyGroup>
</Project>

C:\Windows\FileSystem\\Release_netcoreapp3.1

webpublishmethod webpublishmethod < /code>不是publishurl的一部分,因为它在publishurl下方。

不知道f:\ work \ foo \ bin \,但是您可以尝试配置和targetFramework Release \ netCoreapp2.1

Had a similar problem using VS2019. Only things that worked for me where environment variables like $(windir) and Properties in the pubxml above the line where they are needed e.g.

<!-- removed some properties from xml -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <PublishProvider>FileSystem</PublishProvider>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <PublishUrl>$(WINDIR)\$(PublishProvider)\$(WebPublishMethod)\$(LastUsedBuildConfiguration)_$(TargetFramework)</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
  </PropertyGroup>
</Project>

The resulting PublishUrl was

C:\Windows\FileSystem\\Release_netcoreapp3.1

WebPublishMethod is not part of PublishUrl because it's below PublishUrl.

Don't know about F:\work\foo\bin\ but you could try Configuration and TargetFramework for Release\netcoreapp2.1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文