コード例 #1
0
        /// <summary>
        /// Create a user security checker object that has its main project setup.
        /// </summary>
        internal static UserProjectSecurityChecker CreateUserProjectSecurityChecker(IServiceProvider sp, string fileContents, ProjectShim mainProjectShim)
        {
            string fileName = mainProjectShim.FullFileName + ".user";

            File.WriteAllText(fileName, CleanupProjectXml(fileContents));
            UserProjectSecurityChecker userProjectSecurityChecker = new UserProjectSecurityChecker(sp, fileName);

            PropertyInfo pi = userProjectSecurityChecker.GetType().GetProperty("MainProjectShim", BindingFlags.Instance | BindingFlags.NonPublic);

            pi.SetValue(userProjectSecurityChecker, mainProjectShim, new object[] { });
            return(userProjectSecurityChecker);
        }
コード例 #2
0
        public void TestImportOnUserProject()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string importedProjFilename = CreateTempFileOnDisk(@"
			                
								<Project xmlns=`msbuildnamespace`>
									<PropertyGroup>
										<ReferencePath>c:\foobar</ReferencePath>
									</PropertyGroup>
								</Project>

							"                            );

                string mainProject = CreateTempFileOnDisk(@"                
			                   
								 <Project DefaultTargets=`Build`  xmlns=`msbuildnamespace`>
									<Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets`/>
							   </Project>
							"                            );

                ProjectShim mainProjectShim            = null;
                UserProjectSecurityChecker userProject = null;
                try
                {
                    mainProjectShim = CreateProjectShim(mainProject);
                    userProject     = CreateUserProjectSecurityChecker(sp, String.Format(@"
			                
								<Project DefaultTargets=`Build`  xmlns=`msbuildnamespace`>                      
								  <Import Project=`{0}`/>
							   </Project>
							"                            , importedProjFilename), mainProjectShim);

                    MethodInfo mi    = userProject.GetType().GetMethod("IsProjectSafeWithImports", BindingFlags.Instance | BindingFlags.NonPublic);
                    string[] message = new string[1] {
                        String.Empty
                    };
                    bool result = (bool)mi.Invoke(userProject, message);

                    Assert.IsTrue(!result && !String.IsNullOrEmpty(message[0]), "A user project contained imports and was not considered unsafe.");
                }
                finally
                {
                    TestProjectForSecurity.CleanUp(userProject, mainProjectShim);
                    File.Delete(importedProjFilename);
                }
            });
        }
コード例 #3
0
        /// <summary>
        /// Create a user security checker object that has its main project setup.
        /// </summary>
        internal static UserProjectSecurityChecker CreateUserProjectSecurityChecker(IServiceProvider sp, string fileContents, ProjectShim mainProjectShim)
        {
            string fileName = mainProjectShim.FullFileName + ".user";
            File.WriteAllText(fileName, CleanupProjectXml(fileContents));
            UserProjectSecurityChecker userProjectSecurityChecker = new UserProjectSecurityChecker(sp, fileName);

            PropertyInfo pi = userProjectSecurityChecker.GetType().GetProperty("MainProjectShim", BindingFlags.Instance | BindingFlags.NonPublic);
            pi.SetValue(userProjectSecurityChecker, mainProjectShim, new object[] { });
            return userProjectSecurityChecker;
        }