Open sandboxFocusImprove this doc

Sharing Source Code With Unlicensed Teams

A license is required to create or modify code that uses PostSharp. A license is not required to build code that uses PostSharp but that you did not write yourself.

PostSharp distinguishes the two situations by reading the status of your source control repository. If the working copy contains modifications relative to the base commit, PostSharp considers that you are creating or modifying the code, and requires a valid license.

The source control check is disabled by default, because it executes an external process at every build. As long as it is disabled, PostSharp requires a valid license for every build. You can enable the check in the PostSharp configuration file of your project or solution. See Configuring Projects Using postsharp.config.

Enabling the source control check

To enable source code sharing with unlicensed teams:

  1. Open the file postsharp.config that is located in the root directory of your solution or project. If the file doesn't exist then create a new postsharp.config file in that location with the following content:

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration">
    </Project>
    
  2. Add a Property element under the Project element, set the Name attribute to VcsCheckEnabled and the Value attribute to True.

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration">
        <Property Name="VcsCheckEnabled" Value="True" />
    </Project>
    

How PostSharp determines that a project is unmodified

PostSharp performs the source control check only when it is needed. It first tries to satisfy the license requirements of the weaved aspects with the license keys installed for the current user, then with a redistribution license embedded in the assembly that defines the aspect. The source control check is performed at most once per compilation.

The check proceeds in the following steps:

  1. PostSharp reads the list of source files of the compiled assembly from its debug symbols.

  2. For each source file, PostSharp looks for a repository in the parent directories. A directory that contains a .git subdirectory identifies a Git repository. A directory that contains a file with the .vssscc extension identifies a Team Foundation Version Control repository. Source files that belong to no repository are ignored, but at least one repository must be found.

  3. For each repository, PostSharp executes the source control tool once, in the root directory of the repository. The command is git status --porcelain for Git, and tf status for Team Foundation Version Control.

  4. PostSharp then looks for the source files of the current compilation in the output of the tool. The project is considered modified when one of these files has a modified working copy. Changes to files that are not compiled into the current project do not make the project modified.

If the project is unmodified, PostSharp adds an unlimited internal license to the set of licenses available for this compilation.

Requirements and limitations

  • The supported source control systems are Git and Team Foundation Version Control. If you use another system, PostSharp always requires a license at build time.

  • For Git, the git command must be present in the PATH environment variable of the build process. For Team Foundation Version Control, PostSharp searches the tf.exe command in the installation directory of Visual Studio 2013, 2015 or 2017. If PostSharp cannot execute the command, the project is considered modified.

  • The debug symbols of the compiled assembly must be available, because PostSharp reads the list of source files from them. If the project is compiled without debug symbols, PostSharp cannot determine which source files to check, and the project is considered modified.

On a build server, you do not need this feature. PostSharp detects unattended builds and grants a different internal license in this situation, except for the features of PostSharp Logging. See Using PostSharp on a Build Server.

Diagnosing the source control check

PostSharp writes the result of the source control check to the licensing trace. See Capturing licensing diagnostic logs for the procedure.

The trace reports whether the project was found modified, and names the first modified file. It also reports the situations in which the check could not be performed, for instance when the debug symbols are not available, when no repository was found, or when the source control tool could not be executed.

See Also

Other Resources

License Audit
Investigating Unexpected License Usage
Using PostSharp on a Build Server
Configuring Projects Using postsharp.config