Beispiel #1
0
 def build(self, csproj_path, configuration, msbuild_path, rebuild):
     """
     Builds C Sharp project (.csproj). Simply wraps msbuild command.
     :param path: Path to the .csproj or a directory containing one
     :param configuration: Build configuration - Debug/Release
     :param msbuild_path: Path to the msbuild executable
     :param rebuild: If set, forces msbuild to rebuild the project
     :return:
     """
     csproj_path = self._locate_csproj_at_path(csproj_path)
     msbuild_path = self._locate_msbuild_path(msbuild_path)
     msbuild = MsBuildRunner(msbuild_path, self.debug)
     return msbuild.build(csproj_path, configuration, rebuild)
Beispiel #2
0
    def _locate_msbuild_path(self, msbuild_path):
        """
        Locates mbuild executable path from user input or MsBuild facade.
        @:raises click.UsageError
        """
        # If Msbuild path is provided, check if it's valid
        if msbuild_path:
            if not MsBuildRunner.valid_msbuild_executable(msbuild_path):
                raise click.UsageError(msbuild_path + " is not a valid msbuild executable.")
            else:
                return msbuild_path

        # Msbuild path was not provided, locate
        msbuild_path = MsBuildRunner.locate_msbuild()
        if msbuild_path:
            return msbuild_path

        if not self.quiet:
            click.secho('Failed to locate msbuild executable.')
            click.secho('You can install msbuild as part of the Visual Studio package: '
                        'https://visualstudio.microsoft.com/vs/')
        raise click.UsageError('Failed to locate msbuild executable.')
Beispiel #3
0
 def test_msbuild_runner_locate_msbuild_when_dotnet_framework_installed_win32(self, mock_call, mock_sys):
     """Test MsBuildRunner.locate_msbuild - returns msbuild path in the local system using .NET Framework path """
     if sys.platform != 'win32': # TODO: Fix unit test compatibility on non-windows platform
         return
     mock_call.return_value = 0
     mock_sys.configure_mock(platform='win32')
     vs_msbuild_dir = os.path.normpath("Microsoft.NET\\Framework\\1.0\\")
     msbuild_name = "MSBuild.exe"
     with temp_dir() as tmp_root_dir:
         from ugetcli import msbuild
         with patch.dict(msbuild.os.environ, {'ProgramFiles': tmp_root_dir, 'WINDIR': tmp_root_dir}, clear=True):
             msbuild_dir_path = os.path.join(tmp_root_dir, vs_msbuild_dir)
             os.makedirs(msbuild_dir_path)
             msbuild_path = os.path.join(msbuild_dir_path, msbuild_name)
             create_empty_file(msbuild_path)
             assert MsBuildRunner.locate_msbuild() == msbuild_path
Beispiel #4
0
 def test_msbuild_build_with_rebuild(self, mock_popen, mock_escape_exe_path):
     """Test MsBuildRunner.build - rebuilds .csproj """
     mock_process_instance = MagicMock()
     mock_popen.return_value = mock_process_instance
     mock_process_instance.wait.return_value = 0
     mock_escape_exe_path.return_value = "msbuild.exe"
     with temp_dir() as tmp_root_dir:
         msbuild_path = os.path.join(tmp_root_dir, "msbuild.exe")
         project_path = os.path.join(tmp_root_dir, "Project.csproj")
         create_empty_file(msbuild_path)
         create_empty_file(project_path)
         configuration = "Debug"
         msbuild = MsBuildRunner(msbuild_path)
         msbuild.build(project_path, configuration, True)
         expected_command = 'msbuild.exe {project_path} /t:Clean,Build /p:"Configuration={configuration}" /p:"DebugType=full"' \
                            ' /verbosity:{verbosity}'.format(project_path=project_path, configuration=configuration,
                                                             verbosity="minimal")
         mock_popen.assert_called_with(expected_command, shell=True)
         mock_process_instance.wait.assert_called()
Beispiel #5
0
 def test_msbuild_runner_locate_msbuild_returns_none_when_non_win32_when_not_found(self, mock_call, mock_sys):
     """Test MsBuildRunner.locate_msbuild - returns msbuild on non-windows platform when msbuild is executable """
     mock_call.return_value = -1
     mock_sys.configure_mock(platform='darwin')
     assert MsBuildRunner.locate_msbuild() == None