Publish from Visual Studio and automatically encrypt appSettings using aspnet_regiis Publish from Visual Studio and automatically encrypt appSettings using aspnet_regiis asp.net asp.net

Publish from Visual Studio and automatically encrypt appSettings using aspnet_regiis


After going through your all edits and a bit of research from me , you want to execute the following command after the publish from the Visual Studio

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pe "appSettings" -site Default -app "/" 

If i understood right , You can try wrapping the ItemGroup in a Target with AfterTargets set to AddIisSettingAndFileContentsToSourceManifest

<Target Name="executeinHosts" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">    <ItemGroup>      <MsDeploySourceManifest Include="runCommand">         //here would be your path that need to run after the publish      </MsDeploySourceManifest>    </ItemGroup>  </Target>

So in Your case this is how that part should look:

<Target Name="executeinHosts" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">    <ItemGroup>      <MsDeploySourceManifest Include="runCommand">         <path>C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pe "appSettings" -site $(DeployIisAppPath) -app "/"</path>      </MsDeploySourceManifest>    </ItemGroup>  </Target>

Additional Info:

  • AddIisSettingAndFileContentsToSourceManifest target works justright before Web Deploy copying files from local to server.
  • aspnet_regiis can be run in <target> node by <Exec>.

Ex:

<Exec Command="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pef connectionStrings $(ProjectDir)obj\Debug\Package\PackageTmp" WorkingDirectory="$(publishUrl)" />