Database project won't drop table on publish via Visual Studio - sql-server-data-tools

I have a database project opened in visual studio 2022. I create a new table and when I execute my publish profile I can see in SSMS it has added the new table.
I now try to delete the table within the db project designer, rebuild solution and then attempt to execute my publish profile again.
The table is not dropped and the same is reflected in the publish script.
I have tried with the "Register as data-tier-application" on and off.
Within the Project settings I have also tried ticking "Drop objects in target but not in source" as suggested in this answer
Publish.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="Current">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>Potato.FromDacPacCreation</TargetDatabaseName>
<DeployScriptFileName>Potato.Database.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=localhost;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False</TargetConnectionString>
<BlockWhenDriftDetected>False</BlockWhenDriftDetected>
<RegisterDataTierApplication>True</RegisterDataTierApplication>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
<ItemGroup>
<SqlCmdVariable Include="HostingLocationDomain">
<Value>RandomAdAccountOmitted</Value>
</SqlCmdVariable>
<SqlCmdVariable Include="PasswordForAdAccount">
<Value>DefaultTestPassword</Value>
</SqlCmdVariable>
</ItemGroup>
</Project>

Related

Visual Studio 2017 ASP.Net Publish Self-Contained Dot Net Core App

I have a .Net Core ASP.Net application in Visual Studio 2017. I am trying to do a self contained deployment of the application.
If I run the following command from the CLI it works exactly how I want and produces a .exe
dotnet publish -c release -r win7-x64
However if I publish from Visual Studio 2017 it does not produce a .exe and produces a .dll instead.
How can I replicate the -r win7-x64 of the dotnet publish command from within Visual Studio 2017?
Here is the contents of my .pubxml
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.1</PublishFramework>
<ProjectGuid>74bc47dd-6787-420d-804f-3f3d689d5ae5</ProjectGuid>
<publishUrl>C:\Deploy\JLM.MS.LeadGen.Dealer</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
</PropertyGroup>
</Project>
This experience has been added to the publish window for Visual Studio 2017 version 15.3 (which can be downloaded here)
If you right click on your project -> Publish -> click the "Settings..." link under "Summary" -> go to the Settings tab of the Publish window, you should see a Target Runtime dropdown where you can choose which platform you want your app to run on. Here's a screenshot of what I'm talking about.
Make sure in your project file to include the runtime you want to select in <RuntimeIdentifiers> or <RuntimeIdentifier>, as the dropdown looks for these properties in order to populate its values.
You need to add
<OutputType>Exe</OutputType>
to your .csproj

How to prevent deleting of a folder while publishing an ASP.Net project

I'm working on an ASP.NET Project which can be published on a server by right-clicking the project in the project explorer of Visual Studio and selecting "Publish".
On the server is a folder called "pictures" which shall not be removed while publishing.
So i added a wpp.targets file to my project (in the same folder as the csproj file), but it seems to be that this file doesn't work when i use the publish function of VS.
What can be the cause for it?
This is my wpp.targets file:
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeSetACLProviderOnDestination>False</IncludeSetACLProviderOnDestination>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipDeletingPicturesFolder">
<SkipAction>Delete</SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>pictures</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
drag and drop a file into the pictures folder in solution explorer.then publish. your folder will now be available after publishing. I usually just drop a random image into the folder. remember the file has to be dropped into the folder in the solution explorer and not using your windows file explorer. having a file in your folder basically tell that this folder needs to be published.

WebDeploy: Exclude a specific DLL from a deployment package

How do I tell Web Deploy to exclude a particular DLL file from a web deployment package?
This answer https://stackoverflow.com/a/27404527 offers the advice to exclude the DB2 database driver IBM.Data.DB2.dll from the bin folder of a web application. Otherwise you get an BadImageFormatException in IIS because Visual Studio package the wrong version of the DLL with the web app. I just ran into this issue and tried to follow the advice.
Unfortunately I could not convice Web Deploy to omit this particular DLL. I read this blog post
http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx
and added this
<ItemGroup>
<ExcludeFromPackageFiles Include="$(OutputPath)IBM.Data.DB2.dll">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
but without success. I can still find the DB driver unter _PublishedWebsites\MyWebApp\bin\IBM.Data.DB2.dll in the Binaries folder.
I tried to address my issue again after some time and now it works. Here is the solution. I put it in a file called projectname.wpp.targets alongside the project definition file projectname.csproj.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFiles Include="bin\IBM.Data.DB2.dll">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
</Project>

MSBUILD script building solution, but not deploying publishing profile

I have created a publishing profile for my web page, and I can successfully publish using the web deploy interface in Visual Studio (right click project, deploy etc). It builds the project on my local PC, and copies the files across to destination IIS server.
But now I am trying to create a MSBuild command, which should do the same, but it is only building the solution, not copying it across to the server.
My MSbuild command looks like this, and I run it from the solution source directory
msbuild "test.co.za.sln" p:DeployOnBuild=true /p:PublishProfile="test.co.za" /p:UserName="domain\test" /p:Password="test"
Is there anything wrong with my build command? As you can see in the screenshot, it is building successfully, but no files are being copied across. Which makes me wonder if the publishing profile is executed at all.
I have tried various combinations of publishprofile paths, full paths, with extensions, without, nothing seems to copy my files accross.
My publishing profile looks like this App_Data\Publishprofile\test.co.za.pubxml
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<SiteUrlToLaunchAfterPublish>http://test.co.za</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<MSDeployServiceURL>test.co.za</MSDeployServiceURL>
<DeployIisAppPath>test.co.za</DeployIisAppPath>
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<UserName>domain\test</UserName>
<_SavePWD>True</_SavePWD>
</PropertyGroup>
</Project>
EDIT: This is an existing classic ASP website which I added to a solution, it doesn't contain a ".csproj" file, just a "website.publishproj", which doesn't seem to execute
It doesn't look like you are passing in the VisualStudioVersion property. You should include that. The value will either be 11.0, 12.0, or 14.0 based on the version of Visual Studio you are using. You should likely pass in a value for Configuration as well but it's not required. I've blogged about why this is important at http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx.
You can find the docs for asp.net command line publishing at http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/command-line-deployment
Looks like my "website.publishingproj" is never being built when I run the msbuild command. Not sure why, #Sayed do you perhaps know?
I had to create a targets file next to my solution called "after.solutionName.sln.targets" and copy the code from this answer : https://stackoverflow.com/a/15138373/1184603
<!--?xml version="1.0" encoding="utf-8"?-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Deploy Website" AfterTargets="Build">
<Message Text="Starting Website deployment" Importance="high">
</Message>
<MSBuild Projects="$(MSBuildProjectDirectory)\MyWebs\website.publishproj"
BuildInParallel="true" />
</Target>
</Project>
It now publishes correctly from my msbuild script.

How to publish a full website without compiling and without copying SVN files

Apparently, DNN installations do not like to be precompiled (they won't be able to find any localized strings then). Our installation is safely put in SVN, which means I cannot just copy the whole directory. To publish everything, I need to copy the whole website directory without the SVN files and directories. So far, I've been messing with good old DOS commands, which is time consuming and error prone.
Can someone help me to an MS-Built script or step to do just this? Or can I do this using default Visual Studio 2010 commands?
Note: this is a website, not a web application.
Just svn export the directory from source control, which will give you a clean copy without the .svn stuff in it.
Visual Studio -> Solution Explorer -> <web site> -> <right click> -> Publish Web Site or Copy Web Site
If you are ever interested in automating this with MSBuild then you can do that with something like the following.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<FilesToCopy Include="**\*"
Exclude="**\.svn\**"/>
</ItemGroup>
<PropertyGroup>
<Dest>C:\temp\dest\</Dest>
</PropertyGroup>
<Target Name="CopyFiles">
<Message Text="FilesToCopy: #(FilesToCopy)"/>
<MakeDir Directories="$(Dest)"/>
<Copy SourceFiles="#(FilesToCopy)"
DestinationFiles="#(FilesToCopy->'$(Dest)%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>
So when I create the FilesToCopy item I exclude all the files under any .svn folder. Then I just perform the copy inside the CopyFiles target.

Resources