When I deploy my project from visual studio everything is fine, I have a module with some pictures in it and a stylesheet that get replaced on deployment, from the output window:

  Retracting solution 'xxx.web.wsp'...
  Deleting solution 'xxx.web.wsp'...
Add Solution:
  Found 3 deployment conflict(s).  Resolving conflicts ...
  Deleted file 'http://server/SiteAssets/Style.css' from server.
  Deleted file 'http://server/SiteAssets/pic1.png' from server.
  Deleted file 'http://server/SiteAssets/pic2.png' from server.
  Adding solution 'xxx.web.wsp'...
  Deploying solution 'xxx.web.wsp'...
Activate Features:
  Activating feature 'Feature1' 

Feature1 adds the images back.

However, when I deploy with PowerShell the images/stylesheet are not replaced. I am not sure what I am missing as I deactivate the feature, retract/remove the solution, add/install the solution and activate the feature but the stylesheet and images have not been updated.

Some PS (I have multiple site collections):

$webs =  get-spsite -webapplication "http://server/" -Limit All
$wsp = "xxx.web.wsp"
$path = "C:\xxx.web.wsp"

$Solution = Get-SPSolution | ? {($_.Name -eq $wsp) -and ($_.Deployed -eq $true)}

$feature1 = Get-SPFeature "d56ba933-9c24-440c-9470-1da208c3085e"

$webs | Get-SPSite -limit all | ForEach-Object {
    if ($_.Features[$feature1.ID]) {
        Disable-SPFeature $feature1 -Url $_.Url -Force -Confirm:$false

Uninstall-SPFeature $feature1 -Confirm:$false

Uninstall-SPSolution -Identity $wsp -AllWebApplications -Confirm:$false

Write "Uninstalling" 

while ($Solution.JobExists)
    Start-Sleep 2
    Write "."

Write "Removing solution"

Remove-SPSolution -Identity $wsp -Confirm:$false

Write "Adding solution"

Add-SPSolution -LiteralPath $path 

Write "Installing solution"

Install-SPSolution -Identity $wsp -GACDeployment -AllWebApplications -Force

while ($Solution.JobExists)
    Start-Sleep 2
    Write "."

write "Activate features"
  $feature = "d56ba933-9c24-440c-9470-1da208c3085e" 

  Foreach ($oneweb in $webs)
    write-host $oneweb
    $siteFeature = get-spfeature -site $oneweb | Where {$_.id -eq $feature}
    if ($siteFeature -eq $null)
      Enable-SPFeature -Identity $feature -URL $oneweb.URL -Confirm:$False -Force
      Write-Host "Feature $feature is already activated on $oneweb" -foregroundcolor green

How come Visual Studio deployment deletes the images but powershell doesn't?

Thanks in advance.

1 Answer 1


Physical files are not usually removed from the Library once a solution gets removed. What you have in Visual Studio is actually specific behaviour to VS replacing on re-deployment, not removing upon deactivation.

You would need to do 2 things:

  1. Make sure you add the your module files attributes to IgnoreIfAlreadyExists="FALSE" Type="GhostableInLibrary"
  2. Code the Feature Deactivating code to remove files - even better
  • Hi Marius, I have actually used the code at sharepoint.stackexchange.com/questions/20162/… and it works fine when deploying from visual studio but when I use powershell the feature is deactivated/activated but the code in the eventreceiver is not run for some reason. When I use the gui and deactivate the feature manually it also works, but not with powershell.
    – John
    Oct 5, 2012 at 0:16
  • Your listing from VS suggest that your event receiver isn't doing it's job when running from VS either are you sure it's working? Try remove -Force from your PowerShell it should only be used if everything is screwed up. Oct 6, 2012 at 17:35
  • Ok the issue was that I didn't include Path in the module declaration for the masterpage/page layouts like in the example I posted in my first comment, sorry about that. For VS this didn't matter for some reason.
    – John
    Oct 11, 2012 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.