Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSBuildWorkspace cannot compile project #10629

Closed
JoshVarty opened this issue Apr 15, 2016 · 2 comments
Closed

MSBuildWorkspace cannot compile project #10629

JoshVarty opened this issue Apr 15, 2016 · 2 comments
Labels
Area-IDE Resolution-Duplicate The described behavior is tracked in another issue

Comments

@JoshVarty
Copy link
Contributor

Version Used: Microsoft.CodeAnalysis 1.2.1

Steps to Reproduce:

  1. Sample project (one project, one file) at: https://github.com/JoshVarty/MSBuildWorkspaceBug
  2. Use the following to try to build the project:
//Replace with the correct filepath
var filePath = @"C:\Users\JoshVarty\Documents\GitHub\MSBuildWorkspaceBug\MSBuildWorkspaceBug.sln";
var msbws = MSBuildWorkspace.Create();
var soln = msbws.OpenSolutionAsync(filePath).Result;

foreach(var proj in soln.Projects)
{
    var name = proj.Name;
    var compilation = proj.GetCompilationAsync().Result;
    var errors = compilation.GetDiagnostics().Where(n => n.Severity == DiagnosticSeverity.Error).ToList();
}
  1. Observe the following four errors:
C:\Users\JoshVarty\Documents\GitHub\MSBuildWorkspaceBug\raw\RawAssemblyAttributes.cs(12,11): error CS0246: The type or namespace name 'CLSCompliantAttribute' could not be found (are you missing a using directive or an assembly reference?)
C:\Users\JoshVarty\Documents\GitHub\MSBuildWorkspaceBug\raw\RawAssemblyAttributes.cs(12,11): error CS0246: The type or namespace name 'CLSCompliant' could not be found (are you missing a using directive or an assembly reference?)
C:\Users\JoshVarty\Documents\GitHub\MSBuildWorkspaceBug\raw\RawAssemblyAttributes.cs(12,24): error CS0518: Predefined type 'System.Boolean' is not defined or imported
C:\Users\JoshVarty\Documents\GitHub\MSBuildWorkspaceBug\raw\RawAssemblyAttributes.cs(11,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)

Expected Behavior:

Compiles without errors as it does within Visual Studio.

I'm assuming there are problems with the references, so I'll include the .csproj here as well:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{C18D303B-2C55-43EB-A3DF-39CF3FB1D447}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>raw</RootNamespace>
    <AssemblyName>raw</AssemblyName>
    <WarningLevel>4</WarningLevel>
    <StartupObject>
    </StartupObject>
    <AssemblyOriginatorKeyFile>
    </AssemblyOriginatorKeyFile>
    <AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
    <SignAssembly>true</SignAssembly>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <OldToolsVersion>2.0</OldToolsVersion>
    <UpgradeBackupLocation />
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>..\..\..\bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <RunCodeAnalysis>true</RunCodeAnalysis>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugSymbols>false</DebugSymbols>
    <Optimize>true</Optimize>
    <OutputPath>..\..\..\bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="RawAssemblyAttributes.cs" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System">
      <HintPath>..\..\..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
      <Visible>False</Visible>
      <ProductName>Windows Installer 3.1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
  <PropertyGroup Condition="">
    <PreBuildEvent>
    </PreBuildEvent>
  </PropertyGroup>
</Project>
@JoshVarty
Copy link
Contributor Author

If I add:

<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

to the first PropertyGroup it seems to compile correctly.

@Pilchie
Copy link
Member

Pilchie commented Apr 21, 2016

It sounds like this is a dupe of #5389.

@Pilchie Pilchie closed this as completed Apr 21, 2016
@Pilchie Pilchie added the Resolution-Duplicate The described behavior is tracked in another issue label Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

4 participants