question

xnl28 avatar image
xnl28 asked

Copy a file to target server when deploying

Can't work out how to do this, can anyone give some tips? I have a dataabse project in Visual Studio 2010. The project includes a CSV file. I intend to import this CSV file at deploy time in the post-deployment script via something like BULK INSERT table FROM '$(DefaultLogPath)\Data.csv' but I can't find out how to copy the file to the DefaultLogPath.
visual-studio-2010visualstudio
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
Take a look at the pre and post deployment tasks. You should be able to put in a command line copy statement, or even a powershell call, from there.
6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

xnl28 avatar image xnl28 commented ·
That's what I was thinking. But I need to reference both the source path and the destination path, which will be a UNC folder on the target SQL server. How do I reference the target SQL server name from within a post-deploy task?
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Hmmm... Have you tried using the server name variable? If not, then you might want to go a little more old school. Build a batch file that calls the command line for deployments, passing in your server name and then uses that same information to perform the file copy. We had to do that for a lot of our deployments.
0 Likes 0 ·
xnl28 avatar image xnl28 commented ·
How do I reference the server name variable from within the post-build event command line?
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Oooh, I knew you'd ask that. I don't have VS installed currently to look it up. Look at the properties for the project and then find the tab that has the variables on it. You'll see the exact syntax. It's something like %%server_name%%.
0 Likes 0 ·
xnl28 avatar image xnl28 commented ·
I don't see anything like %%server_name%% in the macros available for the post-build events in the Build Events tab. These are the macros I see there $(CatalogPropertiesFile) $(Configuration) $(DefaultLogin) $(DefaultSchema) $(DefaultUser) $(DeploymentConfigFile) $(DeployToDatabase) $(DeployToScript) $(DSP) $(FinalDeployScriptFile) $(FinalTargetConnectionString) $(FinalTargetDatabase) $(ModelCollation) $(OutputPath) $(ProjectDir) $(ProjectName) $(ServerPropertiesFile) $(SolutionDir) $(SolutionExt) $(SolutionFileName) $(SolutionName) $(SolutionPath) $(SqlCommandVariablesFile)
0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.