PostSharp targets have been imported twice in the project.

ajohnston's Avatar

ajohnston

20 Oct, 2017 06:00 PM

Hi, I've been stuck on this small issue for a few days now. Any advice or ideas would be appreciated, because it's keeping me from compiling.

Error:
PostSharp targets have been imported twice in the project. Be sure to set the 'DontImportPostSharp' property to 'True' when you import PostSharp manually, so that it does not get imported automatically. (1, 1)

Compiled Images Installed:
5.0.35

PostSharp Extension Version:
5.0.35

PostSharp NuGet Packages:
5.0.35

Contents of my .csproj are attached as a text file "targets.txt". I have triple checked it to make sure that there is only one <Import> attribute for the PostSharp targets.

Let me know if you think of anywhere I can search other than the .csproj! I'm not sure where it's seeing this double import problem because the error is as unspecific as possible.

  1. 1 Posted by ajohnston on 20 Oct, 2017 07:02 PM

    ajohnston's Avatar

    Hello, I have also attached a diagnostic level build log where this error is detailed. I'm trying to understand what went wrong. I will keep you up to date if I find anything.

    Please see Line 85 => Line 89 from the log to see where the error is reported.

    Building target "PostSharp30Core" completely.

    Output file "C:\Users\ajohnston\Source\Repos\gk-netcore\Group.Common\obj\Debug\Group.Common.dll.postsharp" does not exist.

    Using "Error" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

    Task "Error" (TaskId:44)

    14:42:38.565 1>C:\Users\ajohnston\Source\Repos\gk-netcore\packages\PostSharp.5.0.35\build\PostSharp.targets(146,5): error : PostSharp targets have been imported twice in the project. Be sure to set the 'DontImportPostSharp' property to 'True' when you import PostSharp manually, so that it does not get imported automatically.

  2. Support Staff 2 Posted by PostSharp Techn... on 23 Oct, 2017 09:36 AM

    PostSharp Technologies's Avatar

    Hello,

    I don't see any problem in attached csproj file. Unfortunately the build log is not complete, so it is not possible to diagnose the problem in more detail. Please, could you send us full build log with diag verbosity?

    Please, do you have PostSharp 2.x installed on your computer? Please, could you check that ..\packages\PostSharp.5.0.35\build\PostSharp.props does exist relatively to your project file?

    -jakub

  3. 3 Posted by ajohnston on 23 Oct, 2017 05:13 PM

    ajohnston's Avatar

    Hi, thanks for taking a look at what I've posted so far. Here's the full diagnostic log attached. I've also attached Postsharp.props in the path that you specified relative to my project file.

    As for Postsharp 2.x, no I only started using it recently so the earliest I've used is version 4.x. I've done a manual wipe of Postsharp on the system as well just in case.

  4. 4 Posted by ajohnston on 24 Oct, 2017 07:43 PM

    ajohnston's Avatar

    Hi, I found this in my postsharp.targets file:

        <!-- Check that PostSharp targets have not been imported twice. -->
        <Error Text="PostSharp targets have been imported twice in the project. Be sure to set the 'DontImportPostSharp' property to 'True' when you import PostSharp manually, so that it does not get imported automatically."
               Condition="'$(_PostSharp30ImportedTwice)'=='True'"/>
    

    Where can I trace the variable $( _PostSharp30ImportedTwice ) ? I'm looking around for when and where that is being set right now.

    This is also in the build log, showing that True is being set, just not sure how it's being set:

    
    14:42:37.425     1>Project "C:\Users\ajohnston\Source\Repos\gk-netcore\GateKeeper.Common\GateKeeper.Common.csproj" on node 1 (rebuild target(s)).
    14:42:37.425     1>Initial Properties:
                       
                       _PostSharp30ImportedTwice = True
    
  5. 5 Posted by ajohnston on 24 Oct, 2017 08:01 PM

    ajohnston's Avatar

    If I modify my targets so that it ignores the variable $(_PostSharp30ImportedTwice) then I can build but get an exception at runtime. I have attached the exception for you, just in case this helps!

  6. Support Staff 6 Posted by PostSharp Techn... on 25 Oct, 2017 05:40 PM

    PostSharp Technologies's Avatar

    Hello,

    thank you for additional information.

    It seems very strange. Please, do you use Resharper build? If yes, please could you try to use standard Visual Studio build instead? Please, could you try to disable PostSharp Visual Studio extension?

    Best regards,
    -jakub

  7. Support Staff 7 Posted by PostSharp Techn... on 06 Nov, 2017 02:56 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  8. PostSharp Technologies closed this discussion on 06 Nov, 2017 02:56 PM.

  9. ajohnston re-opened this discussion on 06 Nov, 2017 11:49 PM

  10. 8 Posted by ajohnston on 06 Nov, 2017 11:49 PM

    ajohnston's Avatar

    Sorry for the delay. I had to put this issue on hold since it was interrupting my work. Here's what I've tried since we last spoke:

    1.) Disabling Postsharp extension causes a build failure.

    2.) VSBuild fails with the same error as Resharper build. I've attached the new build log.

    3.) I reformatted Windows and reinstalled all programs including Postsharp. This error still persists, but it is local to my machine. Other computers can build the code just fine using Postsharp. Your guess is as good as mine, because I've wiped the registry, environment variables, and the OS installation itself and still it breaks the build.

  11. Support Staff 9 Posted by PostSharp Techn... on 21 Nov, 2017 09:55 AM

    PostSharp Technologies's Avatar

    Hello,

    thank you for more information.

    1) It is very strange, that disabling Postsharp extension causes a build failure. Please, does it mean that if you enable PostSharp extension then the build is OK?
    2) Please, could you do another build with VSBuild but with diag verbosity?
    3) Please, could you check that you don't have _PostSharp30ImportedTwice environment variable (both user and machine wide)?

    -jakub

  12. 10 Posted by ajohnston on 21 Nov, 2017 04:57 PM

    ajohnston's Avatar

    1.) No, enabling or disabling postsharp both resulted in build failures. Disabling it was the recommendation of the technician earlier in this thread.

    2.) VSBuild with Diag Verbosity is attached to my previous post.

    3.) I checked everywhere from my registry to my environment vars to every project file and not one of them contains _PostSharp30ImportedTwice.

  13. Support Staff 11 Posted by PostSharp Techn... on 24 Nov, 2017 11:22 AM

    PostSharp Technologies's Avatar

    Hello,

    thank you for additional information and for your patience.

    I apologize, the build log is too brief and it doesn't contain information that is usual for the diag verbosity, that has confused me.

    Please, could you rebuild your solution from developer command prompt and send us the output?

    msbuild <your solution> /t:rebuild /v:diag
    

    Please, could you type set on command line and send us the output also? Maybe there will be some other variable that causes the problem and can be enforced by some domain rule (if you are connected to any windows domain).

    Best regards,
    -jakub

  14. Support Staff 12 Posted by PostSharp Techn... on 06 Dec, 2017 10:34 AM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  15. PostSharp Technologies closed this discussion on 06 Dec, 2017 10:34 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac