以数据库为先决条件的 ClickOnce 部署

发布于 2024-10-13 11:49:16 字数 1479 浏览 1 评论 0原文

我有一个 Winforms 应用程序,想要使用 ClickOnce 发布。该应用程序附带一个初始数据库,必须在每台计算机上安装一次。经过一番周折,我想到了使用自定义先决条件来安装 .sdf 文件的想法。我已经使用 Bootstrapper Manifest Generator (BMG) 为我想要运行的 .cmd 文件创建了一个包,并且我已将 .sdf 文件作为“附加文件”包含在内。

我的期望是这两个文件最终会在同一个目录中,并且我能够将 .sdf 文件复制到我想要的位置(它们最终会在同一个目录中。)先决条件出现在 Visual Studio 中就好了。它被很好地部署到客户端系统,并且安装程序也很好地启动了先决条件。

唯一的问题是 .cmd 文件正在执行的当前工作目录是 C:\Documents and Settings\\Desktop!

这两个文件(.cmd 或 .sdf)都不位于此处 - 它们是在其他地方下载的,例如“C:\Documents and Settings\drogers\Local Settings\Temp\VSD5A.tmp”。因此,虽然我知道要复制到哪里,但我不知道要从哪里复制。

我该如何解决这个问题?

这是 .cmd 文件:

REM Modify this file to reflect your manufacturer name [FHCRC] and product name [ClickOnceSharedDataDemo].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\FHCRC" mkdir "%TargetBase%\FHCRC"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" mkdir "%TargetBase%\FHCRC\ClickOnceSharedDataDemo"
CACLS "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" /E /T /C /G "Users":C
xcopy shareddata.sdf "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" PAUSE
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" exit /B -1
:EXIT
PAUSE
exit /B 0

谢谢, 大卫

I have a Winforms application that I want to publish using ClickOnce. This application comes with an initial database, which must be installed once on a per-machine basis. After much ado, I have landed on the idea of using a custom pre-requisite to install the .sdf file. I have used Bootstrapper Manifest Generator (BMG) to create a package for the .cmd file I want to run, and I have included the .sdf file as an "additional file."

My expectation was that the two files would end up in the same directory, and I would be able to copy the .sdf file to the place where I want it (They do end up in the same directory.) The pre-requisite shows up in Visual Studio just fine. It get's deployed to the client system just fine, and the setup program kicks off the prerequisite just fine.

The only problem is that the current working directory that the .cmd file is executing is C:\Documents and Settings\\Desktop!

Neither of the two files (.cmd or .sdf) are located there - they were downloaded elsewhere, e.g., "C:\Documents and Settings\drogers\Local Settings\Temp\VSD5A.tmp". So, although I know where to xcopy to, I have no idea where to xcopy from.

How can I resolve this?

Here is the .cmd file:

REM Modify this file to reflect your manufacturer name [FHCRC] and product name [ClickOnceSharedDataDemo].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\FHCRC" mkdir "%TargetBase%\FHCRC"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" mkdir "%TargetBase%\FHCRC\ClickOnceSharedDataDemo"
CACLS "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" /E /T /C /G "Users":C
xcopy shareddata.sdf "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" PAUSE
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" exit /B -1
:EXIT
PAUSE
exit /B 0

Thanks,
David

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

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

发布评论

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

评论(2

国产ˉ祖宗 2024-10-20 11:49:16

嗯,我对这个解决方案不太满意,但它确实有效。我现在有两个先决条件。第一个只是运行 CACLS 命令来设置权限的命令文件。它基本上是上述内容的缩短版本:

REM Modify this file to reflect your manufacturer name [Manufacturer] and product name [ProductName].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\Manufacturer\ProductName\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\Manufacturer" mkdir "%TargetBase%\Manufacturer"
if not exist "%TargetBase%\Manufacturer\ProductName" mkdir "%TargetBase%\Manufacturer\ProductName"
CACLS "%TargetBase%\Manufacturer\ProductName" /E /T /C /G "Users":C
:EXIT
ECHO exit /B 0

第二个先决条件是“所有用户= true”安装项目,该项目在默认位置有一个自定义文件夹:
“[CommonAppDataFolder][制造商][产品名称]”。
我将 sdf 文件放入此文件夹中。

最后,我使用 Bootstrapper Manifest Generator 为两者制作包,使第二个依赖于第一个。我将这些包复制到相应的 VS2010 目录,将它们作为先决条件包含在内,然后发布。

我现在已将每台计算机的 .sdf 文件发布到 WinXP 和 Win7。为什么这必须如此困难!?!?

我仍在寻找不太复杂的解决方案,可以安装到 Windows 7 和 Windows XP。

Well, I am not altogether happy with this solution, but it works. I now have two prerequisites. the first is just the command file which runs the CACLS commands to set permissions. It is basically a shortened version of the above:

REM Modify this file to reflect your manufacturer name [Manufacturer] and product name [ProductName].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\Manufacturer\ProductName\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\Manufacturer" mkdir "%TargetBase%\Manufacturer"
if not exist "%TargetBase%\Manufacturer\ProductName" mkdir "%TargetBase%\Manufacturer\ProductName"
CACLS "%TargetBase%\Manufacturer\ProductName" /E /T /C /G "Users":C
:EXIT
ECHO exit /B 0

The second prerequisite is an "all users = true" setup project which has a custom folder located at default location:
"[CommonAppDataFolder][Manufacturer][ProductName]".
Into this folder I put the sdf file.

Finally, I used Bootstrapper Manifest Generator to make packages for both, making the second dependent on the first. I copied the packages to the appropriate VS2010 directory, included them as prerequisites, and published.

I now have per-machine .sdf files published to both WinXP and Win7. Why does this have to be so difficult!?!?

I'm still looking for less complicated solutions, that will install to both Windows 7 and Windows XP.

じее 2024-10-20 11:49:16

您尝试过 MSDeploy 吗?它能够满足您的所有需求。

干杯!

Did you try MSDeploy? It is able to fulfil all your needs.

Cheers!

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