WebApplication 发布到相对文件系统路径

发布于 2024-11-18 11:50:56 字数 200 浏览 3 评论 0原文

我正在设置发布到相对路径以进行本地测试(尤其是 xml 配置转换)。每个开发人员都有自己的签出项目路径,我想设置一个与机器/环境无关的发布。

发布对话框不提示其中允许的任何变量或通配符,并且不接受 obj\publishfile://./obj/publish

有没有办法发布到相对文件系统路径?

I'm setting up a publish to a relative path for testing locally (especially xml config transformations). Each developer has their own path to the checked out project and I'd like to set up a publish that is machine/environment agnostic.

The publish dialog doesn't hint at any variables or wildcards that are allowed in it and it doesn't accept obj\publish or file://./obj/publish

Is there a way to publish to a relative filesystem path?

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

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

发布评论

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

评论(6

爱给你人给你 2024-11-25 11:50:56

对于使用 Visual Studio 2012 和新发布配置文件 (Properties/PublishProfiles/Local.pubxml) 的用户,您可以在文件本身中使用此语法:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <publishUrl>$(MSBuildThisFileDirectory)..\..\obj\publish</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

请注意,$(MSBuildThisFileDirectory) 属性将解析为Local.pubxml 目录。从那里你应该向上移动到达你需要去的地方。

For those using Visual Studio 2012 and the new publish configuration file (Properties/PublishProfiles/Local.pubxml) you can use this syntax in the file itself:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <publishUrl>$(MSBuildThisFileDirectory)..\..\obj\publish</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

Be aware that the $(MSBuildThisFileDirectory) property will resolve to the Local.pubxml directory. From there you should traverse up to get where you need to be.

稚气少女 2024-11-25 11:50:56

编辑

对于 Visual Studio 2012,此解决方案将不起作用。你应该看看 michielvoo 在这个问题之后的答案。

原始答案

设置来使用相对路径

file:///./obj/publish

经过尝试和尝试,我找到了解决方案:您可以通过在 Publish WebApp 对话框中 ,但您必须使用您正在使用的用户已经存在且可写的路径。这样您就可以在本地文件夹或路径相关文件夹中发布您的 Web 应用程序。

让我知道这是否有帮助。它对我有用。

Edit

For Visual Studio 2012, this solution will not work. You should look at the answer by michielvoo just after this one.

Original answer

After trying and trying I found the solution: you can use a relative path by setting

file:///./obj/publish

in the Publish WebApp dialog, but you must use a path that is already existent and writable by the user you are using. This way you can publish your web app in a local folder, or a path related folder.

Let me know if this helps. It did for me.

陪我终i 2024-11-25 11:50:56

在 Visual Studio 2012 中,只有带有正斜杠的常规路径有效:

../../../../../app

这从已发布项目的根目录开始。

Just a regular path with forward slashes works in Visual Studio 2012:

../../../../../app

This starts at the published project's root directory.

浪荡不羁 2024-11-25 11:50:56

这在 Visual Studio 2013 中对我有用:

file:\\..\..\..\Publish

请注意,这不会像原始发布者想要的那样发布到 obj\publish,而是按照我的需要发布到系统上的另一个目录(上面的几个文件夹)。如果您愿意,请将其修改为 obj\publish。

This worked for me in Visual Studio 2013:

file:\\..\..\..\Publish

Please note that this doesn't publish to obj\publish, as the original poster wanted, but to another directory (a few folders up) on my system as I desired. Modify it for obj\publish if you wish.

画▽骨i 2024-11-25 11:50:56

VS 2015 接受类似的内容,

..\..\..\DeployFiles

如果缺少该文件夹,它也会创建该文件夹,因此您的发布设置可以进入源代码管理,但您可以轻松忽略 DeployFiles 文件夹及其内容。

VS 2015 accepts something like

..\..\..\DeployFiles

It will also create the folder if it is missing so your publish settings can go into source control but you can easily ignore the DeployFiles folder and its contents.

幻想少年梦 2024-11-25 11:50:56

对于额外的发布后步骤需要使用相对路径调用 msdeploy(MSVS 2015,dnx)的情况,另一种选择是编辑项目文件(不是 pubxml,尽管这也可能有效)并创建一个变量,该变量是相对路径转换为绝对路径。

<Target Name="AfterWebPublish" AfterTargets="WebPublish">
     <!-- 
          msdeploy cannot currently handle relative paths for contentPath so first convert it to an absolute path 
     -->    
    <PropertyGroup>
        <AbsOutDir>$([System.IO.Path]::GetFullPath("$(ProjectDir)$(OutDir)"))</AbsOutDir>
    </PropertyGroup>

    <Exec WorkingDirectory="$(ProjectDir)" Command='call "$(DevEnvDir)..\Tools\vsvars32.bat"' />    
    <Exec WorkingDirectory="$(ProjectDir)" Command='"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy" -verb:sync -source:contentPath="$(AbsOutDir)PublishOutput" -dest:package="$(AbsOutDir)$(MSBuildProjectName).zip"' />
  </Target>

然后 $(AbsOutDir) 可以根据需要在其他地方使用(例如 msdeploy contentPath)。我认为它不能在对话框中输入。

来自“how-can-i-get-msbuild-to-evaluate-and-print-the-full-path-when-given- a-亲戚”。

For the case where an additional post publish step needs to call msdeploy (MSVS 2015, dnx) with a relative path, another alternative is to edit project file (not the pubxml although that may work too) and create a variable that is the conversion of the relative path into an absolute path.

<Target Name="AfterWebPublish" AfterTargets="WebPublish">
     <!-- 
          msdeploy cannot currently handle relative paths for contentPath so first convert it to an absolute path 
     -->    
    <PropertyGroup>
        <AbsOutDir>$([System.IO.Path]::GetFullPath("$(ProjectDir)$(OutDir)"))</AbsOutDir>
    </PropertyGroup>

    <Exec WorkingDirectory="$(ProjectDir)" Command='call "$(DevEnvDir)..\Tools\vsvars32.bat"' />    
    <Exec WorkingDirectory="$(ProjectDir)" Command='"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy" -verb:sync -source:contentPath="$(AbsOutDir)PublishOutput" -dest:package="$(AbsOutDir)$(MSBuildProjectName).zip"' />
  </Target>

Then $(AbsOutDir) can be used elsewhere as needed (such as for msdeploy contentPath). I don't think it can be entered within the dialog.

From "how-can-i-get-msbuild-to-evaluate-and-print-the-full-path-when-given-a-relative".

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