I need to exclude a reference when the solution is published

587 Views Asked by At

There is a reference we are using in our solution that is causing a problem when we deploy the code.

The reference is System.Management.Automation. When we publish solution we archive the files using EncryptionWizard 3.4.13 (the government edition) then burn the archive file to a DVD and take it to a separate location and expand it on the production server. The archive and expand functions encrypt and decrypts the files.

During the expand when it gets to the System.Management.Automation.dll it stops decryption.

There is really nothing we can do with EncryptionWizard but we should be able to make changes to fix that so we want to exclude System.Management.Automation being published.

We want this to accomplish this using the Publish function in Visual Studio 2017 rather than using MSBuild.

I found some code online that doesn't work for me. in the csprog file for my project I put the following code:

<None Update="System.Management.Automation" CopyToPublishDirectory = "Never"/>

And then I tried this:

<None Update="bin\System.Management.Automation.dll"> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None>

When I look at the bin folder the System.Management.Automation.dll is always there.

If I set the System.Management.Automation reference's Copy Local property to false then I cannot start my web application in Visual Studio without an error, however my deploy problem is solved.

I want to be able to set the Copy Local to true but exclude the System.Management.Automation.dll file from the published files.

1

There are 1 best solutions below

0
On

The solution was to create an xml file called [Your Project Name].wpp.targets in your project folder and add code like this:

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup> 
    <ExcludeFromPackageFiles Include="[dll path and name]">
      <FromTarget>[Any text]</FromTarget>
    </ExcludeFromPackageFiles>
  </ItemGroup>
</Project>

For some reason the code has to be entered by hand and not copy and pasted. At least in my case because if I copied and pasted Visual Studio for whatever reason would not recognize it.

Not all of the Solution Configurations worked. I have one called "Live" and another called "Test" that works. It didn't work in "Debug" and I didn't try "Release".