2013-12-11 114 views
0

我繼承了數據庫項目。預部署腳本未包含在發佈腳本中

它有很多表和st程序的創建語句。 和由於某些原因,所有表沒有外鍵。

所以我創建表的外鍵,當我發佈時,我看到ALTER TABLE生成 但數據不乾淨,因此它在發佈過程中產生一個錯誤。

我發現我可以有預部署腳本(生成操作=預部署) ,所以我說有一條線,支持外鍵

delete from [AccountBalance] where UserId not in (select userid from [user]) 

但是當我生成腳本發佈它不存在。

爲什麼?

更新 發送項目代碼

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 
    <PropertyGroup> 
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> 
    <SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists> 
    <VisualStudioVersion Condition="'$(SSDTExists)' == ''">10.0</VisualStudioVersion> 
    <IncludeSchemaNameInFileName>False</IncludeSchemaNameInFileName> 
    <TargetFrameworkProfile /> 
    </PropertyGroup> 
    <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> 
    <PropertyGroup> 
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 
    <SccProvider>SAK</SccProvider> 
    <SccAuxPath>SAK</SccAuxPath> 
    <SccLocalPath>SAK</SccLocalPath> 
    <SccProjectName>SAK</SccProjectName> 
    <UpgradedFromDBP>True</UpgradedFromDBP> 
    <Name>dbpProjectName</Name> 
    <SchemaVersion>2.0</SchemaVersion> 
    <ProjectVersion>4.1</ProjectVersion> 
    <ProjectGuid>{f43cbd44-bbab-48f6-949d-47c9042bb406}</ProjectGuid> 
    <DSP>Microsoft.Data.Tools.Schema.Sql.Sql100DatabaseSchemaProvider</DSP> 
    <OutputType>Database</OutputType> 
    <RootPath> 
    </RootPath> 
    <SccProvider>SAK</SccProvider> 
    <SccAuxPath>SAK</SccAuxPath> 
    <SccLocalPath>SAK</SccLocalPath> 
    <SccProjectName>SAK</SccProjectName> 
    <UpgradedFromDBP>True</UpgradedFromDBP> 
    <RootNamespace>dbpProjectName</RootNamespace> 
    <PostUpgradeAddToSCC>;C:\Users\travis\Documents\FR\Projects\Fr\Trunk\Fr.Database\Fr.Database.sqlproj;C:\Users\travis\Documents\FR\Projects\Fr\Trunk\Fr.Database\Connections.txt</PostUpgradeAddToSCC> 
    <SccProvider> 
    </SccProvider> 
    <SccAuxPath> 
    </SccAuxPath> 
    <SccLocalPath> 
    </SccLocalPath> 
    <SccProjectName> 
    </SccProjectName> 
    <UpgradedFromDBP>True</UpgradedFromDBP> 
    <AssemblyName>dbpProjectName</AssemblyName> 
    <ModelCollation>1033, CI</ModelCollation> 
    <DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure> 
    <DeployToDatabase>True</DeployToDatabase> 
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> 
    <TargetLanguage>CS</TargetLanguage> 
    <AppDesignerFolder>Properties</AppDesignerFolder> 
    <SqlServerVerification>False</SqlServerVerification> 
    <TargetDatabaseSet>True</TargetDatabaseSet> 
    </PropertyGroup> 
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 
    <OutputPath>bin\Release\</OutputPath> 
    <BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName> 
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors> 
    <DebugType>pdbonly</DebugType> 
    <Optimize>true</Optimize> 
    <DefineDebug>false</DefineDebug> 
    <DefineTrace>true</DefineTrace> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    </PropertyGroup> 
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
    <BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName> 
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors> 
    <DebugSymbols>true</DebugSymbols> 
    <DebugType>full</DebugType> 
    <Optimize>false</Optimize> 
    <DefineDebug>true</DefineDebug> 
    <DefineTrace>true</DefineTrace> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    </PropertyGroup> 
    <!-- VS10 without SP1 will not have VisualStudioVersion set, so do that here --> 
    <PropertyGroup /> 
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Integration|AnyCPU' "> 
    <OutputPath>bin\Debug\</OutputPath> 
    <BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName> 
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors> 
    <DebugSymbols>true</DebugSymbols> 
    <DebugType>full</DebugType> 
    <Optimize>false</Optimize> 
    <DefineDebug>true</DefineDebug> 
    <DefineTrace>true</DefineTrace> 
    <ErrorReport>prompt</ErrorReport> 
    <WarningLevel>4</WarningLevel> 
    </PropertyGroup> 
    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" /> 
    <ItemGroup> 
    <Folder Include="Properties" /> 
    <Folder Include="Cleanup Scripts" /> 
    <Folder Include="Pre-Deploy" /> 
    <Folder Include="Post-Deploy" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Folder Include="Change Scripts" /> 
    <Folder Include="Create Scripts" /> 
    <Folder Include="Data" /> 
    <Folder Include="Functions" /> 
    <Folder Include="Queries" /> 
    <Folder Include="Views" /> 
    <Folder Include="Properties" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Build Include="Create Scripts\AccountBalance.sql" /> 
    <Build Include="Create Scripts\AccountTransaction.sql" /> 
    <Build Include="Create Scripts\ActivityType.sql" /> 
    <Build Include="Create Scripts\Bl.sql" /> 
    <Build Include="Create Scripts\Butter.sql" /> 
    <Build Include="Create Scripts\ButterStash.sql" /> 
    <Build Include="Create Scripts\ButterTransfer.sql" /> 
    <Build Include="Create Scripts\City.sql" /> 
    <Build Include="Create Scripts\Contact.sql" /> 
    <Build Include="Create Scripts\Fan.sql" /> 
    <Build Include="Create Scripts\Friend.sql" /> 
    <Build Include="Create Scripts\Fr.sql" /> 
    <Build Include="Create Scripts\FrLevel.sql" /> 
    <Build Include="Create Scripts\FrLevelQuestion.sql" /> 
    <Build Include="Create Scripts\FrLevelQuestionResult.sql" /> 
    <Build Include="Create Scripts\FrLevelStatus.sql" /> 
    <Build Include="Create Scripts\FrMessage.sql" /> 
    <Build Include="Create Scripts\FrPlayer.sql" /> 
    <Build Include="Create Scripts\FrPlayerStatus.sql" /> 
    <Build Include="Create Scripts\FrQuestion.sql" /> 
    <Build Include="Create Scripts\FrStatus.sql" /> 
    <Build Include="Create Scripts\Invite.sql" /> 
    <Build Include="Create Scripts\InviteSource.sql" /> 
    <Build Include="Create Scripts\InviteType.sql" /> 
    <Build Include="Create Scripts\Lookup.sql" /> 
    <Build Include="Create Scripts\Message.sql" /> 
    <Build Include="Create Scripts\MessageActivity.sql" /> 
    <Build Include="Create Scripts\MessageRecipient.sql" /> 
    <Build Include="Create Scripts\MessageType.sql" /> 
    <Build Include="Create Scripts\PasswordReset.sql" /> 
    <Build Include="Create Scripts\Prize.sql" /> 
    <Build Include="Create Scripts\PrizeType.sql" /> 
    <Build Include="Create Scripts\TransactionType.sql" /> 
    <Build Include="Create Scripts\User.sql" /> 
    <Build Include="Create Scripts\UserActivity.sql" /> 
    <Build Include="Create Scripts\UserAlternateCountryRequest.sql" /> 
    <Build Include="Create Scripts\UserLogin.sql" /> 
    <Build Include="Create Scripts\UserMedia.sql" /> 
    <Build Include="Create Scripts\UserValidation.sql" /> 
    <NotInBuild Include="Data\ActivityType.sql" /> 
    <NotInBuild Include="Data\ButterValues.sql" /> 
    <NotInBuild Include="Data\CityValues.sql" /> 
    <NotInBuild Include="Data\LookupValues.sql" /> 
    <NotInBuild Include="Data\User_TestData.sql" /> 
    <Build Include="Functions\fn_GetDisplayName.sql" /> 
    <Build Include="Functions\fn_ListToTable.sql" /> 
    <Build Include="Queries\AccountBalanceGet.sql" /> 
    <Build Include="Queries\AccountTransactionCreate.sql" /> 
    <Build Include="Queries\AccountTransactionHasCreditPurchase.sql" /> 
    <Build Include="Queries\BlCreate.sql" /> 
    <Build Include="Queries\BlGetLatest.sql" /> 
    <Build Include="Queries\BlsGet.sql" /> 
    <Build Include="Queries\ButterGet.sql" /> 
    <Build Include="Queries\ButterGetAll.sql" /> 
    <Build Include="Queries\ButterMostPopularGet.sql" /> 
    <Build Include="Queries\ButterStashCreate.sql" /> 
    <Build Include="Queries\ButterStashDelete.sql" /> 
    <Build Include="Queries\ButterStashGet.sql" /> 
    <Build Include="Queries\ButterTransferCreate.sql" /> 
    <Build Include="Queries\ButterTransferGet.sql" /> 
    <Build Include="Queries\CitySearchByName.sql" /> 
    <Build Include="Queries\FanCreate.sql" /> 
    <Build Include="Queries\FanDelete.sql" /> 
    <Build Include="Queries\FanSearch.sql" /> 
    <Build Include="Queries\FansGet.sql" /> 
    <Build Include="Queries\FansOfUserGet.sql" /> 
    <Build Include="Queries\FansOfUserSearch.sql" /> 
    <Build Include="Queries\FriendCreate.sql" /> 
    <Build Include="Queries\FriendDelete.sql" /> 
    <Build Include="Queries\FriendSearch.sql" /> 
    <Build Include="Queries\FriendSearchByName.sql" /> 
    <Build Include="Queries\FriendsGet.sql" /> 
    <Build Include="Queries\FrCreate.sql" /> 
    <Build Include="Queries\FrDelete.sql" /> 
    <Build Include="Queries\FrGet.sql" /> 
    <Build Include="Queries\FrGetAll.sql" /> 
    <Build Include="Queries\FrGetLevelExpired.sql" /> 
    <Build Include="Queries\FrLevelCreate.sql" /> 
    <Build Include="Queries\FrLevelGet.sql" /> 
    <Build Include="Queries\FrLevelIsComplete.sql" /> 
    <Build Include="Queries\FrLevelQuestionClear.sql" /> 
    <Build Include="Queries\FrLevelQuestionCreate.sql" /> 
    <Build Include="Queries\FrLevelQuestionResultUpsert.sql" /> 
    <Build Include="Queries\FrLevelStatusUpdate.sql" /> 
    <Build Include="Queries\FrLevelUpdate.sql" /> 
    <Build Include="Queries\FrMessageCreate.sql" /> 
    <Build Include="Queries\FrMessageDelete.sql" /> 
    <Build Include="Queries\FrMessageGet.sql" /> 
    <Build Include="Queries\FrMessagesGet.sql" /> 
    <Build Include="Queries\FrPlayerAdd.sql" /> 
    <Build Include="Queries\FrPlayerRemove.sql" /> 
    <Build Include="Queries\FrPlayerUpdate.sql" /> 
    <Build Include="Queries\FrQuestionGetAll.sql" /> 
    <Build Include="Queries\FrStart.sql" /> 
    <Build Include="Queries\FrUpdate.sql" /> 
    <Build Include="Queries\FrUpdateFringle.sql" /> 
    <Build Include="Queries\InviteCreate.sql" /> 
    <Build Include="Queries\InviteDelete.sql" /> 
    <Build Include="Queries\InviteDeleteByUserId.sql" /> 
    <Build Include="Queries\InviteGet.sql" /> 
    <Build Include="Queries\InviteGetAll.sql" /> 
    <Build Include="Queries\InviteGetByFrId.sql" /> 
    <Build Include="Queries\InviteGetByUserId.sql" /> 
    <Build Include="Queries\InviteGetSentAll.sql" /> 
    <Build Include="Queries\InviteUpdateAssociateEmailToUserId.sql" /> 
    <Build Include="Queries\InviteUpdateInviteStatus.sql" /> 
    <Build Include="Queries\InviteUpdateUserId.sql" /> 
    <Build Include="Queries\LookupsGet.sql" /> 
    <Build Include="Queries\MessageCreate.sql" /> 
    <Build Include="Queries\MessageDelete.sql" /> 
    <Build Include="Queries\MessageGet.sql" /> 
    <Build Include="Queries\MessageRecipientActionUpdate.sql" /> 
    <Build Include="Queries\MessageRecipientUpdate.sql" /> 
    <Build Include="Queries\MessagesGet.sql" /> 
    <Build Include="Queries\MessagesGetSent.sql" /> 
    <Build Include="Queries\MessageThreadGet.sql" /> 
    <Build Include="Queries\MessageUnreadCountGet.sql" /> 
    <Build Include="Queries\PasswordResetCreate.sql" /> 
    <Build Include="Queries\PasswordResetDelete.sql" /> 
    <Build Include="Queries\PasswordResetGet.sql" /> 
    <Build Include="Queries\PrizeGet.sql" /> 
    <Build Include="Queries\PrizesGet.sql" /> 
    <Build Include="Queries\UserActivityCreate.sql" /> 
    <Build Include="Queries\UserActivityForRelatedUsersGet.sql" /> 
    <Build Include="Queries\UserActivityGet.sql" /> 
    <Build Include="Queries\UserAlternateCountryRequestCreate.sql" /> 
    <Build Include="Queries\UserBrowse.sql" /> 
    <Build Include="Queries\UserCreate.sql" /> 
    <Build Include="Queries\UserFrNameExists.sql" /> 
    <Build Include="Queries\UserGet.sql" /> 
    <Build Include="Queries\UserGetByEmail.sql" /> 
    <Build Include="Queries\UserHasBeenFrer.sql" /> 
    <Build Include="Queries\UserLoginInsert.sql" /> 
    <Build Include="Queries\UserMediaDelete.sql" /> 
    <Build Include="Queries\UserMediaGet.sql" /> 
    <Build Include="Queries\UserMediaList.sql" /> 
    <Build Include="Queries\UserMediaUpsert.sql" /> 
    <Build Include="Queries\UserPasswordUpdate.sql" /> 
    <Build Include="Queries\UserProfileGet.sql" /> 
    <Build Include="Queries\UserProfileUpdate.sql" /> 
    <Build Include="Queries\UserSearch.sql" /> 
    <Build Include="Queries\UserUpdate.sql" /> 
    <Build Include="Queries\UserValidationGet.sql" /> 
    <Build Include="Queries\UserValidationGetByUserId.sql" /> 
    <Build Include="Views\UserSummaryView.sql" /> 
    <Build Include="Create Scripts\MessageTypeGroup.sql" /> 
    <None Include="Data\MessageTypeGroup.sql" /> 
    <Build Include="Queries\UserGetByFbId.sql" /> 
    <PreDeploy Include="Pre-Deploy\Script.PreDeployment1.sql" /> 
    </ItemGroup> 
    <ItemGroup> 
    <None Include="Data\Prize.sql" /> 
    <None Include="Data\PrizeType.sql" /> 
    <None Include="Data\TransactionType.sql" /> 
    <None Include="Cleanup Scripts\CleanFrRelatedTables.sql" /> 
    <None Include="Data\FrLevelStatus.sql" /> 
    <None Include="Data\FrPlayerStatus.sql" /> 
    <None Include="Data\FrQuestion.sql" /> 
    <None Include="Data\FrStatus.sql" /> 
    <None Include="Data\InviteSource.sql" /> 
    <None Include="Data\InviteType.sql" /> 
    <None Include="Data\MessageActivity.sql" /> 
    <None Include="Data\MessageType.sql" /> 
    <None Include="Data\FrReminderTypeValues.sql" /> 
    <None Include="Fr.DevDatabase.publish.xml" /> 
    <None Include="Fr.IntegrationDatabase.publish.xml" /> 
    <None Include="Pre-Deploy\Script1.sql" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Build Include="Create Scripts\Feedback.sql" /> 
    <Build Include="Queries\FeedbackCreate.sql" /> 
    <Build Include="Create Scripts\FrReminder.sql" /> 
    <Build Include="Create Scripts\FrReminderType.sql" /> 
    <Build Include="Queries\FrReminderCreate.sql" /> 
    <Build Include="Queries\FrReminderUpdate.sql" /> 
    <Build Include="Queries\FrReminderDelete.sql" /> 
    <Build Include="Queries\FrReminderUpdateUserId.sql" /> 
    <Build Include="Queries\FrReminderGetPendingWarnings.sql" /> 
    <Build Include="Queries\FrReminderGetPendingExpiries.sql" /> 
    <Build Include="Queries\BlsFromFriendsGet.sql" /> 
    <Build Include="Create Scripts\Counter.sql" /> 
    <Build Include="Queries\CounterGet.sql" /> 
    <Build Include="Queries\CounterSet.sql" /> 
    <Build Include="Queries\UserActivityHide.sql" /> 
    <Build Include="Queries\BlDelete.sql" /> 
    <Build Include="Create Scripts\UserBl.sql" /> 
    <Build Include="Queries\UserBlGet.sql" /> 
    <Build Include="Queries\UserBlCreate.sql" /> 
    <Build Include="Queries\UserBlDelete.sql" /> 
    <Build Include="Queries\BlGet.sql" /> 
    <Build Include="Queries\AccountTransactionGetByFr.sql" /> 
    </ItemGroup> 
    <ItemGroup> 
    <RefactorLog Include="Fr.Database.refactorlog" /> 
    </ItemGroup> 
</Project> 
+1

爲什麼這是失敗的將不明確,除非你共享你的.sqlproj文件或提供更多信息。我嘗試通過使用您在此處顯示的表和部署前腳本創建項目來重現此問題,並且預部署腳本已成功包含在發佈腳本中。您是否可以重新檢查構建操作並確保項目文件已保存?預發佈腳本在發佈時應始終包含在內,因此不明顯,這裏發生了什麼問題 –

+0

已添加項目文件。 – Cherven

+0

項目文件看起來不錯,我嘗試使用與您的項目相同的文件夾結構進行重現,但仍然無法找到問題所在。一些想法: - 去年發佈的SSDT的一個版本存在一個問題,即部分生成的部分生成的預部署腳本丟失。更新到最新。 - 嘗試驗證生成的dacpac中的預部署腳本是否包含predeploy腳本。轉到$(ProjectName)\ bin \ Debug \ ProjectName.dacpac - 將其重命名爲.zip並提取內容。 「predeploy.sql」文件應包含所有預部署腳本。如果丟失了,有什麼不對的 –

回答

1

你知道嗎?

這可能不是你的問題,但我剛剛通過這個約20分鐘難倒和事實證明,這個愚蠢的東西(VS)並沒有將這些東西應用到ACTUAL BUILD之外(所以它必須「按照約定」採用構建腳本,並將它們自動添加到發佈腳本中...

所以,如果你像我一樣,直到現在沒有真正理解「配置管理器」的重要性,那麼你可能沒有注意到,由於某種原因,你的項目(dtabase項目)沒有在此檢查「BUILD」配置(DEBUG/RELEASE),那麼將生成腳本,但不包括前/後部署腳本...

您在輸出窗口中獲得的所有內容都是「跳過」消息,如果您有解決方案中的很多其他項目!

無論如何只是張貼這個,因爲它可能有助於某人。

+0

這是我正在尋找的答案。預部署腳本的更新沒有推送到發佈的腳本。重建項目和/或更新構建配置爲我解決了這個問題。 –