質問

I have several SSDT projects in VS2013 and find myself increasingly interrupted by an annoying build issue for which my online searches have yielded no answers.

Generally these SSDT projects build as expected. However, lately a seemingly random build issue arises sometimes, affecting only one or more SSDT projects - none of the ~50 C# projects in my solution: SSDT fails to find the projects' files because it looks for them in other projects' directories.

For example, here is the output for an SSDT build snagged by this issue, followed by a build of the same SSDT project with the issue cleared (simply by closing and re-opening Visual Studio...or rebooting my machine when that does not work - i.e. no code changes):

Failed Build

------ Build started: Project: MyOrg.SomeSolution.Database, Configuration: Debug Any CPU ------
C:\SCC\SomeSolution\trunk\Database\Source\Scripts\Script.PostDeployment.sql(25,4): Error:  SQL72001: The included file SomeTable.data.sql (C:\SCC\SomeSolution\TRUNK\COMPONENTS\SOMECATEGORY\FOO\FOO.UNIT.TESTS\SCRIPTS\SOMETABLE.DATA.SQL) does not exist.
Done building project "MyOrg.SomeSolution.Database.sqlproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Build Summary
-------------
00:00.506 - Failed  - Debug Any CPU - Database\Source\MyOrg.SomeSolution.Database.sqlproj

Total build time: 00:56.948

========== Build: 0 succeeded or up-to-date, 1 failed, 52 skipped, Completed at 4/24/2014 3:12:01 PM ==========
Publish cannot begin until your project is ready to build.  Try again after resolving any errors in the project.

Successful Build

------ Build started: Project: MyOrg.SomeSolution.Database, Configuration: Debug Any CPU ------
    MyOrg.SomeSolution.Database -> C:\SCC\SomeSolution\trunk\Database\Build\Scripts\MyOrg.SomeSolution.Database.dll
    MyOrg.SomeSolution.Database -> C:\SCC\SomeSolution\trunk\Database\Build\Scripts\MyOrg.SomeSolution.Database.dacpac
    C:\SCC\SomeSolution\trunk\Database\Build\PostBuild.bat
    Generating publish script for database '_TheDatabase_' on server 'localhost'.
    Successfully generated script to file C:\SCC\SomeSolution\trunk\Database\Build\Scripts\MyOrg.SomeSolution.Database.sql.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Build Summary
-------------
00:10.928 - Success - Debug Any CPU - Database\Source\MyOrg.SomeSolution.Database.sqlproj

Total build time: 00:00.000

========== : 1 succeeded or up-to-date, 0 failed, 52 skipped, Completed at 4/24/2014 3:16:11 PM ==========

While the build output above is in the context of publishing, building independent of publishing yields the same results when the issue hits.

Finally, I sense that this issue may arise after Visual Studio detects outside changes to my solution, its projects, and/or their files, then reloads them at my direction; but this is not a hypothesis I have (dis)confirmed with focused experimentation, rather just a suspicion I have developed in the course of my work.

Has anyone else encountered this issue and found a way to squash it?

役に立ちましたか?

解決

Here is the now-proposed fix in the SSDT forum post that @KevinCunnane cited:

<Target Name="SqlBuild"
        Inputs="@(SqlBuildInputItem->'%(FullPath)')"
        Outputs="@(SqlBuildOutputItem)"
        DependsOnTargets="$(SqlBuildDependsOn)">

  <SqlBuildTask
    PostdeployItem="@(PostDeploy->'%(FullPath)')"
    PredeployItem="@(PreDeploy->'%(FullPath)')"
    RefactorLog="@(RefactorLog->'%(FullPath)')"
    SqlTarget="@(SqlTarget)"

These changes are to be made in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" and will be in the next SSDT release planned for later this month.

My first build with the changes succeeded, but...so did my first build with the previously suggested fix in the SSDT forum: I will beat on the now-proposed fix today and report back.

他のヒント

Several years after your question, i encountered the same issue in VS2015 community.

My project settings are: SQL Server 2014; .Net framework 4.6.1

After struggling for several hours i found that

changing
:r .\path\folder\script.sql
into
:r ..\\path\\folder\\script.sql

as well as you need to enable CMDMODE on the postdeployment execution script with right clicking it and selecting the option like this.

enter image description here

This solved the problem with building the SQL Database Project.

Yes, others have run into this issue and there looks to be a possible solution. See this post on the SSDT forum. Here's the relevant information including a suggestion on fixing it:

Our targets file is passing in the relative path of the pre/post build script when the actual code expects an absolute path. In our next release (hopefully around June) the targets file will define SqlScriptDependenciesTask as

<SqlScriptDependenciesTask
  PostdeployItem="@(PostDeploy->'%(FullPath)')"
  PredeployItem="@(PreDeploy->'%(FullPath)')"
  BuildExtensionConfiguration="@(BuildExtensionConfiguration)"
  DeploymentExtensionConfiguration="@(DeploymentExtensionConfiguration)"
  SqlCmdVariables="@(SqlCmdVariables)">

With this we'll be passing the full path to the task as it expects. If anyone wishes to try this solution just open your targets file in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" and edit that definition. By the way, if anyone does try this please let me know the results. thanks!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top